Skip to content

Commit db7ba55

Browse files
authored
Merge branch 'dev' into feat/insert_turtle_here
2 parents c9dfaf8 + 53f6b7d commit db7ba55

6 files changed

Lines changed: 71 additions & 23 deletions

File tree

File renamed without changes.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Since v2.1.0, we're keeping a changelog of each version's changes in NeuroPilot.
66

77
Changes between each version before then will not be listed.
88

9+
## 2.2.3
10+
11+
### Fixes
12+
13+
- Fixed error catching not working in Copilot mode.
14+
- Fixed Delete File not displaying the targeted file in Copilot mode (used to return `undefined`)
15+
916
## 2.2.2
1017

1118
### New settings

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"description": "Allows Neuro-sama to either act as a companion/copilot or control Visual Studio Code by herself.",
66
"icon": "assets/heart-xaendril.png",
7-
"version": "2.2.1",
7+
"version": "2.2.2",
88
"publisher": "VSC-NeuroPilot",
99
"repository": "https://github.com/VSC-NeuroPilot/neuropilot",
1010
"homepage": "https://vsc-neuropilot.github.io/neuropilot",
@@ -962,7 +962,7 @@
962962
}
963963
},
964964
"scripts": {
965-
"preinstall": "node ./scripts/check-malicious-packages.js",
965+
"preinstall": "node ./scripts/check-malicious-packages.js",
966966
"version:changesets": "changeset version --global-changelog",
967967
"push": "tsx ./dual-publish.ts",
968968
"vscode:prepublish": "pnpm build",
@@ -985,7 +985,7 @@
985985
"watch:web:esbuild": "node ./scripts/esbuild.mjs --watch --mode web",
986986
"watch:web:tsc": "tsc --noEmit --watch --project tsconfig.web.json",
987987
"watch:desktop:esbuild": "node ./scripts/esbuild.mjs --watch --mode desktop",
988-
"watch:desktop:tsc": "tsc --noEmit --watch --project tsconfig.app.json",
988+
"watch:desktop:tsc": "tsc --noEmit --watch --project tsconfig.app.json",
989989
"test:web": "pnpm run build:web && npm-run-all -s test:web:tsc test:web:esbuild test:web:browser",
990990
"test:web:tsc": "tsc --noEmit --project test-tsconfigs/tsconfig.web.json",
991991
"test:web:esbuild": "node ./scripts/esbuild.mjs --mode web --test",

src/file_actions.ts

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as vscode from 'vscode';
33

44
import { NEURO } from '@/constants';
5-
import { formatContext, getFence, getPositionContext, getVirtualCursor, getWorkspacePath, getWorkspaceUri, isBinary, isPathNeuroSafe, logOutput, normalizePath } from '@/utils';
5+
import { formatContext, getFence, getPositionContext, getVirtualCursor, getWorkspacePath, getWorkspaceUri, isBinary, isPathNeuroSafe, logOutput, normalizePath, notifyOnCaughtException } from '@/utils';
66
import { ActionData, contextNoAccess, RCEAction, actionValidationFailure, actionValidationAccept, ActionValidationResult, stripToActions } from '@/neuro_client_helper';
77
import { CONFIG, PERMISSIONS, PermissionLevel, getPermissionLevel, isActionEnabled } from '@/config';
88
import { targetedFileCreatedEvent, targetedFileDeletedEvent } from '@events/files';
@@ -43,8 +43,9 @@ async function getUriExistence(uri: vscode.Uri): Promise<boolean> {
4343
try {
4444
await vscode.workspace.fs.stat(uri);
4545
return true;
46-
} catch {
47-
return false;
46+
} catch (erm: unknown) {
47+
if (erm instanceof vscode.FileSystemError && erm.code === 'FileNotFound') return false;
48+
else throw erm;
4849
}
4950
}
5051

@@ -250,7 +251,7 @@ export const fileActions = {
250251
(actionData: ActionData) => targetedFileDeletedEvent(actionData.params?.path),
251252
],
252253
validators: [neuroSafeDeleteValidation],
253-
promptGenerator: (actionData: ActionData) => `delete "${actionData.params?.pathToDelete}".`,
254+
promptGenerator: (actionData: ActionData) => `delete "${actionData.params?.path}".`,
254255
},
255256
} satisfies Record<string, RCEAction>;
256257

@@ -304,13 +305,19 @@ export function handleCreateFile(actionData: ActionData): string | undefined {
304305
// If no error is thrown, the file already exists
305306
NEURO.client?.sendContext(`Could not create file: File ${relativePath} already exists`);
306307
return;
307-
} catch { /* File does not exist, continue */ }
308+
} catch (erm: unknown) {
309+
if ((erm as vscode.FileSystemError).code !== 'FileNotFound') {
310+
notifyOnCaughtException('create_file', erm);
311+
return;
312+
};
313+
/* else, file does not exist, continue */
314+
}
308315

309316
// Create the file
310317
try {
311318
await vscode.workspace.fs.writeFile(fileUri, new Uint8Array(0));
312319
} catch (erm: unknown) {
313-
logOutput('ERROR', `Failed to create file ${relativePath}: ${erm}`);
320+
notifyOnCaughtException('create_file', erm);
314321
NEURO.client?.sendContext(`Failed to create file ${relativePath}`);
315322
return;
316323
}
@@ -353,13 +360,19 @@ export function handleCreateFolder(actionData: ActionData): string | undefined {
353360
// If no error is thrown, the folder already exists
354361
NEURO.client?.sendContext(`Could not create folder: Folder ${relativePath} already exists`);
355362
return;
356-
} catch { /* Folder does not exist, continue */ }
363+
} catch (erm: unknown) {
364+
if ((erm as vscode.FileSystemError).code !== 'FileNotFound') {
365+
notifyOnCaughtException('create_folder', erm);
366+
return;
367+
}
368+
/* else, folder does not exist, continue */
369+
}
357370

358371
// Create the folder
359372
try {
360373
await vscode.workspace.fs.createDirectory(folderUri);
361374
} catch (erm: unknown) {
362-
logOutput('ERROR', `Failed to create folder ${relativePath}: ${erm}`);
375+
notifyOnCaughtException('create_folder', erm);
363376
NEURO.client?.sendContext(`Failed to create folder ${relativePath}`);
364377
return;
365378
}
@@ -393,13 +406,19 @@ export function handleRenameFileOrFolder(actionData: ActionData): string | undef
393406
// If no error is thrown, the new path already exists
394407
NEURO.client?.sendContext(`Could not rename: ${newRelativePath} already exists`);
395408
return;
396-
} catch { /* New path does not exist, continue */ }
409+
} catch (erm: unknown) {
410+
if ((erm as vscode.FileSystemError).code !== 'FileNotFound') {
411+
notifyOnCaughtException('rename_file_or_folder', erm);
412+
return;
413+
};
414+
/* New path does not exist, continue */
415+
}
397416

398417
// Rename the file/folder
399418
try {
400419
await vscode.workspace.fs.rename(oldUri, newUri);
401420
} catch (erm: unknown) {
402-
logOutput('ERROR', `Failed to rename ${oldRelativePath} to ${newRelativePath}: ${erm}`);
421+
notifyOnCaughtException('rename_file_or_folder', erm);
403422
NEURO.client?.sendContext(`Failed to rename ${oldRelativePath} to ${newRelativePath}`);
404423
return;
405424
}
@@ -429,9 +448,14 @@ export function handleDeleteFileOrFolder(actionData: ActionData): string | undef
429448
// Check if the path exists
430449
try {
431450
stat = await vscode.workspace.fs.stat(uri);
432-
} catch {
433-
NEURO.client?.sendContext(`Could not delete: ${relativePath} does not exist`);
434-
return;
451+
} catch (erm: unknown) {
452+
if (erm instanceof vscode.FileSystemError && erm.code === 'FileNotFound') {
453+
NEURO.client?.sendContext(`Could not delete: ${relativePath} does not exist`);
454+
return;
455+
} else {
456+
notifyOnCaughtException('delete_file_or_folder', erm);
457+
return;
458+
}
435459
}
436460

437461
// Check for correct recursive parameter
@@ -570,7 +594,7 @@ export function handleOpenFile(actionData: ActionData): string | undefined {
570594
}
571595
}
572596
} catch (erm: unknown) {
573-
logOutput('ERROR', `Failed to open file ${relativePath}: ${erm}`);
597+
notifyOnCaughtException('open_file', erm);
574598
NEURO.client?.sendContext(`Failed to open file ${relativePath}`);
575599
}
576600
}
@@ -598,7 +622,8 @@ export function handleReadFile(actionData: ActionData): string | undefined {
598622
},
599623
);
600624
} catch (erm: unknown) {
601-
logOutput('ERROR', `Error occured while trying to access file ${file}: ${erm}`);
625+
notifyOnCaughtException('read_file', erm);
626+
NEURO.client?.sendContext(`Unable to read file ${file}`);
602627
}
603628
}
604629

src/lint_problems.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ async function getUriExistence(uri: vscode.Uri): Promise<boolean> {
3737
try {
3838
await vscode.workspace.fs.stat(uri);
3939
return true;
40-
} catch {
41-
return false;
40+
} catch (erm: unknown) {
41+
if (erm instanceof vscode.FileSystemError && erm.code === 'FileNotFound') return false;
42+
else throw erm;
4243
}
4344
}
4445

src/rce.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export interface RceRequest {
4747
* Disposable events
4848
*/
4949
cancelEvents?: vscode.Disposable[]
50+
/**
51+
* The action data associated with this request.
52+
*/
53+
actionData: ActionData;
5054
}
5155

5256
export const cancelRequestAction: RCEAction = {
@@ -103,10 +107,13 @@ export function clearRceRequest(): void {
103107
* Creates a new RCE request and attaches it to NEURO.
104108
* @param prompt The prompt to be displayed in the notification.
105109
* @param callback The callback function to be executed when the request is accepted.
110+
* @param actionData The action data associated with this request.
111+
* @param cancelEvents Optional array of disposables for cancellation events.
106112
*/
107113
export function createRceRequest(
108114
prompt: string,
109115
callback: () => string | undefined,
116+
actionData: ActionData,
110117
cancelEvents?: vscode.Disposable[],
111118
): void {
112119
NEURO.rceRequest = {
@@ -118,6 +125,7 @@ export function createRceRequest(
118125
resolve: () => { },
119126
attachNotification: async () => { },
120127
cancelEvents,
128+
actionData,
121129
};
122130

123131
const promise = new Promise<void>((resolve) => {
@@ -220,9 +228,15 @@ export function acceptRceRequest(): void {
220228

221229
NEURO.client?.sendContext(`${CONNECTION.userName} has accepted your request.`);
222230

223-
const result = NEURO.rceRequest.callback();
224-
if (result)
225-
NEURO.client?.sendContext(result);
231+
try {
232+
const result = NEURO.rceRequest.callback();
233+
if (result)
234+
NEURO.client?.sendContext(result);
235+
} catch (erm: unknown) {
236+
const actionName = NEURO.rceRequest.actionData.name;
237+
notifyOnCaughtException(actionName, erm);
238+
NEURO.client?.sendActionResult(NEURO.rceRequest.actionData.id, true, `An error occured while executing the action "${actionName}". You can retry if you like, but it may be better to ask Vedal to check what's up.`);
239+
}
226240

227241
clearRceRequest();
228242
}
@@ -369,6 +383,7 @@ export async function RCEActionHandler(actionData: ActionData, actionList: Recor
369383
createRceRequest(
370384
prompt,
371385
() => action.handler(actionData),
386+
actionData,
372387
eventArray,
373388
);
374389

0 commit comments

Comments
 (0)