@@ -148,12 +148,12 @@ export class Commands {
148148 public async viewLogs ( ) : Promise < void > {
149149 if ( this . workspaceLogPath ) {
150150 // Return the connected deployment's log file.
151- return this . openFile ( this . workspaceLogPath ) ;
151+ return openFile ( this . workspaceLogPath ) ;
152152 }
153153
154154 const logDir = this . pathResolver . getProxyLogPath ( ) ;
155155 try {
156- const files = await fs . readdir ( logDir ) ;
156+ const files = await readdirOrEmpty ( logDir ) ;
157157 // Sort explicitly since fs.readdir order is platform-dependent
158158 const logFiles = files
159159 . filter ( ( f ) => f . endsWith ( ".log" ) )
@@ -172,7 +172,7 @@ export class Commands {
172172 } ) ;
173173
174174 if ( selected ) {
175- await this . openFile ( path . join ( logDir , selected ) ) ;
175+ await openFile ( path . join ( logDir , selected ) ) ;
176176 }
177177 } catch ( error ) {
178178 vscode . window . showErrorMessage (
@@ -181,11 +181,6 @@ export class Commands {
181181 }
182182 }
183183
184- private async openFile ( filePath : string ) : Promise < void > {
185- const uri = vscode . Uri . file ( filePath ) ;
186- await vscode . window . showTextDocument ( uri ) ;
187- }
188-
189184 /**
190185 * Log out and clear stored credentials, requiring re-authentication on next login.
191186 */
@@ -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