Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 350c04b

Browse files
author
Akos Kitta
committed
Fix the incorrect error message from the CLI.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 95971a2 commit 350c04b

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

‎arduino-ide-extension/src/node/sketches-service-impl.ts‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { promisify } from 'util';
1010
import URI from '@theia/core/lib/common/uri';
1111
import { FileUri } from '@theia/core/lib/node';
1212
import { isWindows, isOSX } from '@theia/core/lib/common/os';
13-
import { ConfigService } from '../common/protocol/config-service';
13+
import { ConfigServiceImpl } from './config-service-impl';
1414
import {
1515
SketchesService,
1616
Sketch,
@@ -50,8 +50,8 @@ export class SketchesServiceImpl
5050
? tempDir
5151
: maybeNormalizeDrive(fs.realpathSync.native(tempDir));
5252

53-
@inject(ConfigService)
54-
protected readonly configService: ConfigService;
53+
@inject(ConfigServiceImpl)
54+
protected readonly configService: ConfigServiceImpl;
5555

5656
@inject(NotificationServiceServerImpl)
5757
protected readonly notificationService: NotificationServiceServerImpl;
@@ -205,7 +205,14 @@ export class SketchesServiceImpl
205205
if (err) {
206206
reject(
207207
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+
)
209216
: err
210217
);
211218
return;
@@ -583,6 +590,36 @@ interface SketchWithDetails extends Sketch {
583590
readonly mtimeMs: number;
584591
}
585592

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+
586623
function isNotFoundError(err: unknown): err is ServiceError {
587624
return ServiceError.is(err) && err.code === 5; // `NOT_FOUND` https://grpc.github.io/grpc/core/md_doc_statuscodes.html
588625
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /