Explorar el Código

fix(phoenix): Gracefully handle completing a non-existent path

filesystem.readdir() can throw, which previously would crash Phoenix and
leave the terminal unresponsive. This change makes it return no results
instead.
Sam Atkins hace 11 meses
padre
commit
d76e7130cb
Se han modificado 1 ficheros con 9 adiciones y 4 borrados
  1. 9 4
      packages/phoenix/src/puter-shell/completers/FileCompleter.js

+ 9 - 4
packages/phoenix/src/puter-shell/completers/FileCompleter.js

@@ -33,12 +33,17 @@ export class FileCompleter {
 
 
         const completions = [];
         const completions = [];
 
 
-        const result = await filesystem.readdir(dir);
-        if ( result === undefined ) {
-            return [];
+        let dir_entries;
+        try {
+            dir_entries = await filesystem.readdir(dir);
+        } catch (e) {
+            // Ignored
         }
         }
 
 
-        for ( const item of result ) {
+        if ( dir_entries === undefined )
+            return [];
+
+        for ( const item of dir_entries ) {
             if ( item.name.startsWith(base) ) {
             if ( item.name.startsWith(base) ) {
                 completions.push(item.name.slice(base.length));
                 completions.push(item.name.slice(base.length));
             }
             }