@@ -27,6 +27,7 @@ import {
27
27
CLOSE_PLOTTER_WINDOW ,
28
28
SHOW_PLOTTER_WINDOW ,
29
29
} from '../../common/ipc-communication' ;
30
+ import isValidPath = require( 'is-valid-path' ) ;
30
31
31
32
app . commandLine . appendSwitch ( 'disable-http-cache' ) ;
32
33
@@ -143,10 +144,12 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
143
144
app . on ( 'open-file' , async ( event , path ) => {
144
145
event . preventDefault ( ) ;
145
146
const resolvedPath = await this . resolvePath ( path , cwd ) ;
146
- const sketchFolderPath = await this . isValidSketchPath ( resolvedPath ) ;
147
- if ( sketchFolderPath ) {
148
- this . openFilePromise . reject ( new InterruptWorkspaceRestoreError ( ) ) ;
149
- await this . openSketch ( sketchFolderPath ) ;
147
+ if ( resolvedPath ) {
148
+ const sketchFolderPath = await this . isValidSketchPath ( resolvedPath ) ;
149
+ if ( sketchFolderPath ) {
150
+ this . openFilePromise . reject ( new InterruptWorkspaceRestoreError ( ) ) ;
151
+ await this . openSketch ( sketchFolderPath ) ;
152
+ }
150
153
}
151
154
} ) ;
152
155
setTimeout ( ( ) => this . openFilePromise . resolve ( ) , 500 ) ;
@@ -198,11 +201,25 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
198
201
}
199
202
}
200
203
201
- private async resolvePath ( path : string , cwd : string ) : Promise < string > {
202
- if ( isAbsolute ( path ) ) {
203
- return path ;
204
+ private async resolvePath (
205
+ maybePath : string ,
206
+ cwd : string
207
+ ) : Promise < string | undefined > {
208
+ if ( ! isValidPath ( maybePath ) ) {
209
+ return undefined ;
210
+ }
211
+ if ( isAbsolute ( maybePath ) ) {
212
+ return maybePath ;
213
+ }
214
+ try {
215
+ const resolved = await fs . realpath ( resolve ( cwd , maybePath ) ) ;
216
+ return resolved ;
217
+ } catch ( err ) {
218
+ if ( 'code' in err && err . code === 'ENOENT' ) {
219
+ return undefined ;
220
+ }
221
+ throw err ;
204
222
}
205
- return fs . realpath ( resolve ( cwd , path ) ) ;
206
223
}
207
224
208
225
protected override async launch (
@@ -236,6 +253,9 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
236
253
) ;
237
254
for ( const workspace of workspaces ) {
238
255
const resolvedPath = await this . resolvePath ( workspace . file , params . cwd ) ;
256
+ if ( ! resolvedPath ) {
257
+ continue ;
258
+ }
239
259
const sketchFolderPath = await this . isValidSketchPath ( resolvedPath ) ;
240
260
if ( sketchFolderPath ) {
241
261
workspace . file = sketchFolderPath ;
@@ -264,6 +284,9 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
264
284
let path : string | undefined ;
265
285
for ( const maybePath of argCopy ) {
266
286
const resolvedPath = await this . resolvePath ( maybePath , params . cwd ) ;
287
+ if ( ! resolvedPath ) {
288
+ continue ;
289
+ }
267
290
const sketchFolderPath = await this . isValidSketchPath ( resolvedPath ) ;
268
291
if ( sketchFolderPath ) {
269
292
path = sketchFolderPath ;
0 commit comments