Skip to content

Commit

Permalink
Merge pull request #67 from SanjulaGanepola/fix/error-messages
Browse files Browse the repository at this point in the history
Fix error handling of files not found
  • Loading branch information
SanjulaGanepola authored Nov 23, 2024
2 parents 0e3c278 + b46f97e commit 76ad59a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class SettingsManager {
const document = await workspace.openTextDocument(settingFileUri);
await window.showTextDocument(document);
} catch (error: any) {
window.showErrorMessage(`Failed to create ${settingFileName}. Error: ${error}`)
window.showErrorMessage(`Failed to create ${settingFileName}. Error: ${error}`);
}
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ export class SettingsManager {
await workspace.fs.stat(Uri.file(settingFile.path));
window.showErrorMessage(`Failed to delete file. Error ${error}`);
return;
} catch (error) { }
} catch (error: any) { }
}

await this.removeSettingFile(workspaceFolder, settingFile, storageKey);
Expand Down
15 changes: 12 additions & 3 deletions src/views/settings/settingsTreeDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, QuickPickItem, QuickPickItemKind, ThemeIcon, TreeCheckboxChangeEvent, TreeDataProvider, TreeItem, TreeItemCheckboxState, window, workspace } from "vscode";
import { CancellationToken, commands, EventEmitter, ExtensionContext, QuickPickItem, QuickPickItemKind, ThemeIcon, TreeCheckboxChangeEvent, TreeDataProvider, TreeItem, TreeItemCheckboxState, Uri, window, workspace } from "vscode";
import { act } from "../../extension";
import { SettingFileName, Visibility } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
Expand Down Expand Up @@ -126,8 +126,17 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
}
}),
commands.registerCommand('githubLocalActions.openSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
const document = await workspace.openTextDocument(settingFileTreeItem.settingFile.path);
await window.showTextDocument(document);
try {
const document = await workspace.openTextDocument(settingFileTreeItem.settingFile.path);
await window.showTextDocument(document);
} catch (error: any) {
try {
await workspace.fs.stat(Uri.file(settingFileTreeItem.settingFile.path));
window.showErrorMessage(`Failed to open file. Error: ${error}`);
} catch (error: any) {
window.showErrorMessage(`File ${settingFileTreeItem.settingFile.name} not found.`);
}
}
}),
commands.registerCommand('githubLocalActions.removeSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
await act.settingsManager.removeSettingFile(settingFileTreeItem.workspaceFolder, settingFileTreeItem.settingFile, settingFileTreeItem.storageKey);
Expand Down
14 changes: 12 additions & 2 deletions src/views/workflows/workflowsTreeDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from "path";
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, window, workspace } from "vscode";
import { Event } from "../../act";
import { act } from "../../extension";
Expand Down Expand Up @@ -37,8 +38,17 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
this.refresh();
}),
commands.registerCommand('githubLocalActions.openWorkflow', async (workflowTreeItem: WorkflowTreeItem) => {
const document = await workspace.openTextDocument(workflowTreeItem.workflow.uri);
await window.showTextDocument(document);
try {
const document = await workspace.openTextDocument(workflowTreeItem.workflow.uri);
await window.showTextDocument(document);
} catch (error: any) {
try {
await workspace.fs.stat(workflowTreeItem.workflow.uri);
window.showErrorMessage(`Failed to open workflow. Error: ${error}`);
} catch (error: any) {
window.showErrorMessage(`Workflow ${path.parse(workflowTreeItem.workflow.uri.fsPath).base} not found.`);
}
}
}),
commands.registerCommand('githubLocalActions.runWorkflow', async (workflowTreeItem: WorkflowTreeItem) => {
await act.runWorkflow(workflowTreeItem.workspaceFolder, workflowTreeItem.workflow);
Expand Down

0 comments on commit 76ad59a

Please sign in to comment.