@@ -30,6 +30,7 @@ import {
30
30
keys ,
31
31
getFolderPathname ,
32
32
generateFolderId ,
33
+ isNoteValidBySchema ,
33
34
} from './utils'
34
35
import { escapeRegExp , generateId , getHexatrigesimalString } from '../string'
35
36
import {
@@ -72,15 +73,22 @@ class FSNoteDb implements NoteDb {
72
73
const missingFolderPathnameSet = new Set < string > ( )
73
74
const missingTagNameSet = new Set < string > ( )
74
75
for ( const note of notes ) {
75
- if ( note . trashed ) {
76
- continue
77
- }
78
- missingFolderPathnameSet . add ( note . folderPathname )
79
- note . tags . forEach ( ( tag ) => {
80
- if ( this . data ! . tagMap [ tag ] == null ) {
81
- missingTagNameSet . add ( tag )
76
+ try {
77
+ if ( note . trashed ) {
78
+ continue
82
79
}
83
- } )
80
+ missingFolderPathnameSet . add ( note . folderPathname )
81
+ note . tags . forEach ( ( tag ) => {
82
+ if ( this . data ! . tagMap [ tag ] == null ) {
83
+ missingTagNameSet . add ( tag )
84
+ }
85
+ } )
86
+ } catch ( e ) {
87
+ console . warn (
88
+ `Skipping note file because it is not valid JSON note document`
89
+ )
90
+ console . log ( note )
91
+ }
84
92
}
85
93
86
94
if ( newStorage ) {
@@ -797,7 +805,14 @@ class FSNoteDb implements NoteDb {
797
805
const rawDoc = await readFileAsString (
798
806
join ( this . location , 'notes' , noteFileName )
799
807
)
800
- notes . push ( JSON . parse ( rawDoc ) as NoteDoc )
808
+ const note = JSON . parse ( rawDoc ) as NoteDoc
809
+ if ( isNoteValidBySchema ( note ) ) {
810
+ notes . push ( note )
811
+ } else {
812
+ console . warn (
813
+ `[WARNING] Invalid note found ${ noteFileName } . Please check if the file is a valid, non-corrupted note data.`
814
+ )
815
+ }
801
816
} catch ( error ) {
802
817
console . error ( error )
803
818
}
0 commit comments