fix: Handle gracefully when trying to detect invalid sketch name error and folder is missing on filesystem (#1616)

- feat: generalized Node.js error handling
    - Gracefully handle when the sketch folder has been deleted
 - feat: spare detecting invalid sketch name error
    - The invalid sketch name detection requires at least one extra FS access.
       Do not try to detect the invalid sketch name error, but use the original
       `NotFound` from the CLI.
 - fix: typo

Closes #1596

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2022-11-10 11:11:35 +01:00
committed by GitHub
parent 3a70547770
commit 6984c52b92
6 changed files with 78 additions and 28 deletions

View File

@@ -28,6 +28,7 @@ import {
SHOW_PLOTTER_WINDOW,
} from '../../common/ipc-communication';
import isValidPath = require('is-valid-path');
import { ErrnoException } from '../../node/utils/errors';
app.commandLine.appendSwitch('disable-http-cache');
@@ -172,7 +173,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
try {
stats = await fs.stat(path);
} catch (err) {
if ('code' in err && err.code === 'ENOENT') {
if (ErrnoException.isENOENT(err)) {
return undefined;
}
throw err;
@@ -215,7 +216,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
const resolved = await fs.realpath(resolve(cwd, maybePath));
return resolved;
} catch (err) {
if ('code' in err && err.code === 'ENOENT') {
if (ErrnoException.isENOENT(err)) {
return undefined;
}
throw err;