@@ -10,7 +10,7 @@ import { promisify } from 'util';
10
10
import URI from '@theia/core/lib/common/uri' ;
11
11
import { FileUri } from '@theia/core/lib/node' ;
12
12
import { isWindows , isOSX } from '@theia/core/lib/common/os' ;
13
- import { ConfigService } from '../common/protocol/ config-service' ;
13
+ import { ConfigServiceImpl } from './ config-service-impl ' ;
14
14
import {
15
15
SketchesService ,
16
16
Sketch ,
@@ -50,8 +50,8 @@ export class SketchesServiceImpl
50
50
? tempDir
51
51
: maybeNormalizeDrive ( fs . realpathSync . native ( tempDir ) ) ;
52
52
53
- @inject ( ConfigService )
54
- protected readonly configService : ConfigService ;
53
+ @inject ( ConfigServiceImpl )
54
+ protected readonly configService : ConfigServiceImpl ;
55
55
56
56
@inject ( NotificationServiceServerImpl )
57
57
protected readonly notificationService : NotificationServiceServerImpl ;
@@ -205,7 +205,14 @@ export class SketchesServiceImpl
205
205
if ( err ) {
206
206
reject (
207
207
isNotFoundError ( err )
208
- ? SketchesError . NotFound ( err . details , uri )
208
+ ? SketchesError . NotFound (
209
+ fixErrorMessage (
210
+ err ,
211
+ requestSketchPath ,
212
+ this . configService . cliConfiguration ?. directories . user
213
+ ) ,
214
+ uri
215
+ )
209
216
: err
210
217
) ;
211
218
return ;
@@ -583,6 +590,36 @@ interface SketchWithDetails extends Sketch {
583
590
readonly mtimeMs : number ;
584
591
}
585
592
593
+ // https://github.com/arduino/arduino-cli/issues/1797
594
+ function fixErrorMessage (
595
+ err : ServiceError ,
596
+ sketchPath : string ,
597
+ sketchbookPath : string | undefined
598
+ ) : string {
599
+ if ( ! sketchbookPath ) {
600
+ return err . details ; // No way to repair the error message. The current sketchbook path is not available.
601
+ }
602
+ // Original: `Can't open sketch: no valid sketch found in /Users/a.kitta/Documents/Arduino: missing /Users/a.kitta/Documents/Arduino/Arduino.ino`
603
+ // Fixed: `Can't open sketch: no valid sketch found in /Users/a.kitta/Documents/Arduino: missing $sketchPath`
604
+ const message = err . details ;
605
+ const incorrectMessageSuffix = path . join ( sketchbookPath , 'Arduino.ino' ) ;
606
+ if (
607
+ message . startsWith ( "Can't open sketch: no valid sketch found in" ) &&
608
+ message . endsWith ( `${ incorrectMessageSuffix } ` )
609
+ ) {
610
+ const sketchName = path . basename ( sketchPath ) ;
611
+ const correctMessagePrefix = message . substring (
612
+ 0 ,
613
+ message . length - incorrectMessageSuffix . length
614
+ ) ;
615
+ return `${ correctMessagePrefix } ${ path . join (
616
+ sketchPath ,
617
+ `${ sketchName } .ino`
618
+ ) } `;
619
+ }
620
+ return err . details ;
621
+ }
622
+
586
623
function isNotFoundError ( err : unknown ) : err is ServiceError {
587
624
return ServiceError . is ( err ) && err . code === 5 ; // `NOT_FOUND` https://grpc.github.io/grpc/core/md_doc_statuscodes.html
588
625
}
0 commit comments