don't throw on vfs load failure

Massimo Melina committed Dec 16, 2021 at 15:15 UTC 2f967e910e2eebd6f065acc7cb3e1ddf30e40d83
2 files changed +15 -7
dev-notes.md
+2 -1
@@ -19,4 +19,5 @@
19 - webdav?
20 - streamable zip archives
21 - no compression
22 - - resumable?
\ No newline at end of file
22 + - resumable?
23 +- vfs: ability to remove/hide/rename files deep in a source
\ No newline at end of file
src/vfs.ts
+13 -6
@@ -21,13 +21,21 @@ export interface VfsNode {
21 rename?: Record<string,string>,
22 }
23
24 +const EMPTY = { type: VfsNodeType.root }
25 +
26 export class Vfs {
25 - root: VfsNode = {}
27 + root: VfsNode = EMPTY
28 watcher?: FSWatcher
29
30 constructor(path?:string) {
31 if (path)
32 this.load(path).then()
33 + else
34 + this.reset()
35 + }
36 +
37 + reset(){
38 + this.root = { ...EMPTY }
39 }
40
41 async load(path: string, watchFile:boolean=true) {
@@ -35,13 +43,12 @@ export class Vfs {
43 try {
44 const data = await fs.readFile(path, 'utf8')
45 this.root = yaml.parse(data)
46 + // we should validate content now
47 + console.debug('loaded')
48 }
39 - catch(e){
40 - return
49 + catch(e) {
50 + console.error(`Load failed for ${path}`)
51 }
42 - if (!this.root)
43 - throw `Load failed for ${path}`
44 - this.root.type = VfsNodeType.root
52 this.watcher?.close()
53 this.watcher = undefined
54 recur(this.root)