editor: show error message on fail to activate

When gotoError fails to activate a file, we need to show an error
message, otherwise it just appears to the user that the button is
broken.

Fixes: https://github.com/pybricks/support/issues/924
This commit is contained in:
David Lechner
2023-02-13 16:13:58 -06:00
committed by David Lechner
parent 8c90854184
commit 0d3447a0b6
2 changed files with 28 additions and 1 deletions
+5
View File
@@ -4,6 +4,11 @@
## [Unreleased]
### Fixed
- Show error message when go to syntax error fails to activate file ([support#924]).
[support#924]: https://github.com/pybricks/support/issues/924
## [2.1.0] - 2023-01-06
### Changed
+23 -1
View File
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import type { DatabaseChangeType, IDatabaseChange } from 'dexie-observable/api';
import * as monaco from 'monaco-editor';
@@ -16,6 +16,7 @@ import {
take,
takeEvery,
} from 'typed-redux-saga/macro';
import { alertsShowAlert } from '../alerts/actions';
import { FileStorageDb, UUID } from '../fileStorage';
import {
fileStorageDidFailToLoadTextFile,
@@ -257,6 +258,27 @@ function* handleEditorGoto(
});
if (didFailToActivate) {
if (
didFailToActivate.error instanceof EditorError &&
didFailToActivate.error.name === 'FileInUse'
) {
const db = yield* getContext<FileStorageDb>('fileStorage');
const metadata = yield* call(() => db.metadata.get(action.uuid));
yield* put(
alertsShowAlert('explorer', 'fileInUse', {
fileName: metadata?.path ?? '<unknown>',
}),
);
} else {
yield* put(
alertsShowAlert('alerts', 'unexpectedError', {
error: didFailToActivate.error,
}),
);
}
return;
}