Skip to content

Commit 8dd710a

Browse files
committed
fix: add error handling for profile export and import functions
1 parent 0c23c46 commit 8dd710a

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/profiles/profileManager.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ export async function exportProfile(context: vscode.ExtensionContext) {
252252
if (!uri) {
253253
return;
254254
}
255-
await vscode.workspace.fs.writeFile(uri, Buffer.from(JSON.stringify(data, null, 2)));
256-
vscode.window.showInformationMessage(`Exported profile to ${uri.fsPath}`);
255+
try {
256+
await vscode.workspace.fs.writeFile(uri, Buffer.from(JSON.stringify(data, null, 2)));
257+
vscode.window.showInformationMessage(`Exported profile to ${uri.fsPath}`);
258+
} catch (e: unknown) {
259+
const msg = e instanceof Error ? e.message : String(e);
260+
vscode.window.showErrorMessage(`Failed to export profile: ${msg}`);
261+
}
257262
}
258263

259264
export async function importProfile(context: vscode.ExtensionContext) {
@@ -262,13 +267,18 @@ export async function importProfile(context: vscode.ExtensionContext) {
262267
return;
263268
}
264269
const uri = uris[0];
265-
const bytes = await vscode.workspace.fs.readFile(uri);
266-
const data = JSON.parse(Buffer.from(bytes).toString('utf8'));
267-
const name = await vscode.window.showInputBox({ prompt: 'Profile name to import as', value: 'imported' });
268-
if (!name) {
269-
return;
270+
try {
271+
const bytes = await vscode.workspace.fs.readFile(uri);
272+
const data = JSON.parse(Buffer.from(bytes).toString('utf8'));
273+
const name = await vscode.window.showInputBox({ prompt: 'Profile name to import as', value: 'imported' });
274+
if (!name) {
275+
return;
276+
}
277+
await context.globalState.update(`profile:${name}`, data);
278+
await context.globalState.update(ACTIVE_PROFILE_KEY, name);
279+
vscode.window.showInformationMessage(`Imported profile "${name}" from ${uri.fsPath}`);
280+
} catch (e: unknown) {
281+
const msg = e instanceof Error ? e.message : String(e);
282+
vscode.window.showErrorMessage(`Failed to import profile: ${msg}`);
270283
}
271-
await context.globalState.update(`profile:${name}`, data);
272-
await context.globalState.update(ACTIVE_PROFILE_KEY, name);
273-
vscode.window.showInformationMessage(`Imported profile "${name}" from ${uri.fsPath}`);
274284
}

0 commit comments

Comments
 (0)