@@ -147,12 +147,12 @@ export class Commands {
147147 public async viewLogs ( ) : Promise < void > {
148148 if ( this . workspaceLogPath ) {
149149 // Return the connected deployment's log file.
150- return this . openFile ( this . workspaceLogPath ) ;
150+ return openFile ( this . workspaceLogPath ) ;
151151 }
152152
153153 const logDir = this . pathResolver . getProxyLogPath ( ) ;
154154 try {
155- const files = await fs . readdir ( logDir ) ;
155+ const files = await readdirOrEmpty ( logDir ) ;
156156 // Sort explicitly since fs.readdir order is platform-dependent
157157 const logFiles = files
158158 . filter ( ( f ) => f . endsWith ( ".log" ) )
@@ -171,7 +171,7 @@ export class Commands {
171171 } ) ;
172172
173173 if ( selected ) {
174- await this . openFile ( path . join ( logDir , selected ) ) ;
174+ await openFile ( path . join ( logDir , selected ) ) ;
175175 }
176176 } catch ( error ) {
177177 vscode . window . showErrorMessage (
@@ -180,11 +180,6 @@ export class Commands {
180180 }
181181 }
182182
183- private async openFile ( filePath : string ) : Promise < void > {
184- const uri = vscode . Uri . file ( filePath ) ;
185- await vscode . window . showTextDocument ( uri ) ;
186- }
187-
188183 /**
189184 * Log out and clear stored credentials, requiring re-authentication on next login.
190185 */
@@ -768,3 +763,22 @@ export class Commands {
768763 } ) ;
769764 }
770765}
766+
767+ async function openFile ( filePath : string ) : Promise < void > {
768+ const uri = vscode . Uri . file ( filePath ) ;
769+ await vscode . window . showTextDocument ( uri ) ;
770+ }
771+
772+ /**
773+ * Read a directory's entries, returning an empty array if it does not exist.
774+ */
775+ async function readdirOrEmpty ( dirPath : string ) : Promise < string [ ] > {
776+ try {
777+ return await fs . readdir ( dirPath ) ;
778+ } catch ( err ) {
779+ if ( err instanceof Error && "code" in err && err . code === "ENOENT" ) {
780+ return [ ] ;
781+ }
782+ throw err ;
783+ }
784+ }
0 commit comments