Skip to content

Commit 0c01db4

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
Show an error message snackbar for directory errors with overrides
Fixed: 412841634 Change-Id: I2849d35c5140f1b6fd3c4a8b76fbd43b4b410cb2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6770020 Commit-Queue: Philip Pfaffe <[email protected]> Auto-Submit: Philip Pfaffe <[email protected]> Reviewed-by: Danil Somsikov <[email protected]>
1 parent 1e2143a commit 0c01db4

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

front_end/entrypoints/main/MainImpl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import * as Workspace from '../../models/workspace/workspace.js';
5555
import * as Snippets from '../../panels/snippets/snippets.js';
5656
import * as Buttons from '../../ui/components/buttons/buttons.js';
5757
import * as IconButton from '../../ui/components/icon_button/icon_button.js';
58+
import * as Snackbar from '../../ui/components/snackbars/snackbars.js';
5859
import * as Components from '../../ui/legacy/components/utils/utils.js';
5960
import * as UI from '../../ui/legacy/legacy.js';
6061
import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
@@ -397,6 +398,9 @@ export class MainImpl {
397398

398399
// Request filesystems early, we won't create connections until callback is fired. Things will happen in parallel.
399400
const isolatedFileSystemManager = Persistence.IsolatedFileSystemManager.IsolatedFileSystemManager.instance();
401+
isolatedFileSystemManager.addEventListener(
402+
Persistence.IsolatedFileSystemManager.Events.FileSystemError,
403+
event => Snackbar.Snackbar.Snackbar.show({message: event.data}));
400404

401405
const defaultThemeSetting = 'systemPreferred';
402406
const themeSetting = Common.Settings.Settings.instance().createSetting('ui-theme', defaultThemeSetting);

front_end/models/persistence/IsolatedFileSystem.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import * as Platform from '../../core/platform/platform.js';
3535
import * as TextUtils from '../text_utils/text_utils.js';
3636

3737
import {Events, type IsolatedFileSystemManager} from './IsolatedFileSystemManager.js';
38-
import {PlatformFileSystem, PlatformFileSystemType} from './PlatformFileSystem.js';
38+
import {Events as PlatformFileSystemEvents, PlatformFileSystem, PlatformFileSystemType} from './PlatformFileSystem.js';
3939

4040
const UIStrings = {
4141
/**
@@ -58,6 +58,17 @@ const UIStrings = {
5858
*@example {example.url} PH1
5959
*/
6060
linkedToS: 'Linked to {PH1}',
61+
/**
62+
*@description Error message shown when devtools failed to create a file system directory.
63+
*@example {path/} PH1
64+
*/
65+
createDirFailedBecausePathIsFile:
66+
'Overrides: Failed to create directory {PH1} because the path exists and is a file.',
67+
/**
68+
*@description Error message shown when devtools failed to create a file system directory.
69+
*@example {path/} PH1
70+
*/
71+
createDirFailed: 'Overrides: Failed to create directory {PH1}. Are the workspace or overrides configured correctly?'
6172
} as const;
6273
const str_ = i18n.i18n.registerUIStrings('models/persistence/IsolatedFileSystem.ts', UIStrings);
6374
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -210,6 +221,13 @@ export class IsolatedFileSystem extends PlatformFileSystem {
210221
private innerCreateFolderIfNeeded(path: string): Promise<DirectoryEntry|null> {
211222
return new Promise(resolve => {
212223
this.domFileSystem.root.getDirectory(path, {create: true}, dirEntry => resolve(dirEntry), error => {
224+
this.domFileSystem.root.getFile(
225+
path, undefined,
226+
() => this.dispatchEventToListeners(
227+
PlatformFileSystemEvents.FILE_SYSTEM_ERROR,
228+
i18nString(UIStrings.createDirFailedBecausePathIsFile, {PH1: path})),
229+
() => this.dispatchEventToListeners(
230+
PlatformFileSystemEvents.FILE_SYSTEM_ERROR, i18nString(UIStrings.createDirFailed, {PH1: path})));
213231
const errorMessage = IsolatedFileSystem.errorMessage(error);
214232
console.error(errorMessage + ' trying to create directory \'' + path + '\'');
215233
resolve(null);

front_end/models/persistence/IsolatedFileSystemManager.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ import * as Platform from '../../core/platform/platform.js';
3535

3636
import type {FilesChangedData} from './FileSystemWorkspaceBinding.js';
3737
import {IsolatedFileSystem} from './IsolatedFileSystem.js';
38-
import {type PlatformFileSystem, PlatformFileSystemType} from './PlatformFileSystem.js';
38+
import {
39+
Events as PlatformFileSystemEvents,
40+
type PlatformFileSystem,
41+
PlatformFileSystemType
42+
} from './PlatformFileSystem.js';
3943

4044
const UIStrings = {
4145
/**
@@ -191,6 +195,7 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
191195
return null;
192196
}
193197
this.fileSystemsInternal.set(fileSystemURL, fileSystem);
198+
fileSystem.addEventListener(PlatformFileSystemEvents.FILE_SYSTEM_ERROR, this.#onFileSystemError, this);
194199
if (dispatchEvent) {
195200
this.dispatchEventToListeners(Events.FileSystemAdded, fileSystem);
196201
}
@@ -200,6 +205,7 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
200205

201206
addPlatformFileSystem(fileSystemURL: Platform.DevToolsPath.UrlString, fileSystem: PlatformFileSystem): void {
202207
this.fileSystemsInternal.set(fileSystemURL, fileSystem);
208+
fileSystem.addEventListener(PlatformFileSystemEvents.FILE_SYSTEM_ERROR, this.#onFileSystemError, this);
203209
this.dispatchEventToListeners(Events.FileSystemAdded, fileSystem);
204210
}
205211

@@ -225,6 +231,10 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
225231
}
226232
}
227233

234+
#onFileSystemError(event: Common.EventTarget.EventTargetEvent<string>): void {
235+
this.dispatchEventToListeners(Events.FileSystemError, event.data);
236+
}
237+
228238
private onFileSystemRemoved(event: Common.EventTarget.EventTargetEvent<Platform.DevToolsPath.RawPathString>): void {
229239
const embedderPath = event.data;
230240
const fileSystemPath = Common.ParsedURL.ParsedURL.rawPathToUrlString(embedderPath);
@@ -233,6 +243,7 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
233243
return;
234244
}
235245
this.fileSystemsInternal.delete(fileSystemPath);
246+
isolatedFileSystem.removeEventListener(PlatformFileSystemEvents.FILE_SYSTEM_ERROR, this.#onFileSystemError, this);
236247
isolatedFileSystem.fileSystemRemoved();
237248
this.dispatchEventToListeners(Events.FileSystemRemoved, isolatedFileSystem);
238249
}
@@ -349,6 +360,7 @@ export enum Events {
349360
FileSystemFilesChanged = 'FileSystemFilesChanged',
350361
ExcludedFolderAdded = 'ExcludedFolderAdded',
351362
ExcludedFolderRemoved = 'ExcludedFolderRemoved',
363+
FileSystemError = 'FileSystemError',
352364
/* eslint-enable @typescript-eslint/naming-convention */
353365
}
354366

@@ -358,6 +370,7 @@ export interface EventTypes {
358370
[Events.FileSystemFilesChanged]: FilesChangedData;
359371
[Events.ExcludedFolderAdded]: Platform.DevToolsPath.EncodedPathString;
360372
[Events.ExcludedFolderRemoved]: Platform.DevToolsPath.EncodedPathString;
373+
[Events.FileSystemError]: string;
361374
}
362375

363376
let lastRequestId = 0;

front_end/models/persistence/PlatformFileSystem.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import type * as Common from '../../core/common/common.js';
5+
import * as Common from '../../core/common/common.js';
66
import * as i18n from '../../core/i18n/i18n.js';
77
import type * as Platform from '../../core/platform/platform.js';
88
import type * as TextUtils from '../text_utils/text_utils.js';
@@ -45,7 +45,15 @@ export enum PlatformFileSystemType {
4545
WORKSPACE_PROJECT = 'workspace-project',
4646
}
4747

48-
export class PlatformFileSystem {
48+
export const enum Events {
49+
FILE_SYSTEM_ERROR = 'file-system-error',
50+
}
51+
52+
interface EventTypes {
53+
[Events.FILE_SYSTEM_ERROR]: string;
54+
}
55+
56+
export class PlatformFileSystem extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
4957
readonly #path: Platform.DevToolsPath.UrlString;
5058
#type: PlatformFileSystemType;
5159
/**
@@ -55,6 +63,7 @@ export class PlatformFileSystem {
5563
readonly automatic: boolean;
5664

5765
constructor(path: Platform.DevToolsPath.UrlString, type: PlatformFileSystemType, automatic: boolean) {
66+
super();
5867
this.#path = path;
5968
this.#type = type;
6069
this.automatic = automatic;

0 commit comments

Comments
 (0)