Skip to content

Commit 889cb2d

Browse files
committed
sessions: handle duplicate dialog failures
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a713c12c-1a43-4f7f-9337-fca7f8dfe89f
1 parent 7d71f12 commit 889cb2d

2 files changed

Lines changed: 49 additions & 20 deletions

File tree

‎src/vs/sessions/contrib/sessions/browser/views/automationsView.ts‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,27 +1355,27 @@ registerAction2(class DuplicateAutomationAction extends Action2 {
13551355
return;
13561356
}
13571357

1358-
const name = getDuplicateAutomationName(automation.name, automationService.automations.get());
1359-
const result = await automationDialogService.showAutomationDialog({
1360-
initialValues: {
1361-
name,
1362-
prompt: automation.prompt,
1363-
schedule: automation.schedule,
1364-
target: automation.target,
1365-
modelId: automation.modelId,
1366-
mode: automation.mode,
1367-
permissionLevel: automation.permissionLevel,
1368-
enabled: automation.enabled,
1369-
},
1370-
});
1371-
if (!result || result.kind !== 'create') {
1372-
return;
1373-
}
1374-
if (!isEnabled()) {
1375-
await showAutomationsDisabled(dialogService);
1376-
return;
1377-
}
13781358
try {
1359+
const name = getDuplicateAutomationName(automation.name, automationService.automations.get());
1360+
const result = await automationDialogService.showAutomationDialog({
1361+
initialValues: {
1362+
name,
1363+
prompt: automation.prompt,
1364+
schedule: automation.schedule,
1365+
target: automation.target,
1366+
modelId: automation.modelId,
1367+
mode: automation.mode,
1368+
permissionLevel: automation.permissionLevel,
1369+
enabled: automation.enabled,
1370+
},
1371+
});
1372+
if (!result || result.kind !== 'create') {
1373+
return;
1374+
}
1375+
if (!isEnabled()) {
1376+
await showAutomationsDisabled(dialogService);
1377+
return;
1378+
}
13791379
const duplicate = await automationService.createAutomation(result.value, () => {
13801380
if (!isEnabled()) {
13811381
throw new Error(localize('automationsDisabledBeforeDuplicate', "Automations were disabled before the duplicate could be saved."));

‎src/vs/sessions/contrib/sessions/test/browser/automationsView.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,35 @@ suite('AutomationsCardsWidget', () => {
899899
});
900900
});
901901

902+
test('duplicate dialog failures are logged and reported to the user', async () => {
903+
const { automationDialogService, automationService, dialogService, instantiationService, logService } = setup();
904+
const source = automation();
905+
const error = new Error('dialog failed');
906+
automationDialogService.error = error;
907+
automationService.setAutomations([source]);
908+
const command = CommandsRegistry.getCommand('sessions.automations.duplicate');
909+
assert.ok(command);
910+
911+
await instantiationService.invokeFunction(accessor => command.handler(accessor, source));
912+
await dialogService.errorCalled.p;
913+
914+
assert.deepStrictEqual({
915+
createCalls: automationService.createCalls,
916+
loggedErrors: logService.errors,
917+
dialogErrors: dialogService.errors,
918+
}, {
919+
createCalls: [],
920+
loggedErrors: [{
921+
message: '[Automations] Failed to duplicate automation',
922+
args: [error],
923+
}],
924+
dialogErrors: [{
925+
message: 'Failed to duplicate automation.',
926+
detail: 'dialog failed',
927+
}],
928+
});
929+
});
930+
902931
test('duplicate creation failures are logged and reported to the user', async () => {
903932
const { automationDialogService, automationService, contextKeyService, contextMenuService, dialogService, instantiationService, logService, widget } = setup();
904933
const source = automation();

0 commit comments

Comments
 (0)