|
1 | 1 | import * as vscode from 'vscode'; |
2 | 2 |
|
3 | | -import { getFence, logOutput, simpleFileName } from '@/utils'; |
| 3 | +import { getFence, logOutput, notifyOnCaughtException, simpleFileName } from '@/utils'; |
4 | 4 | import { NEURO } from '@/constants'; |
5 | 5 | import { PERMISSIONS, PermissionLevel, getPermissionLevel, isActionEnabled } from '@/config'; |
6 | 6 |
|
@@ -53,43 +53,50 @@ export function registerRequestCookieHandler() { |
53 | 53 | if (actionData.name === 'request_cookie') { |
54 | 54 | NEURO.actionHandled = true; |
55 | 55 |
|
56 | | - if (NEURO.waitingForCookie) { |
57 | | - logOutput('INFO', 'Already waiting for a cookie'); |
58 | | - NEURO.client?.sendActionResult(actionData.id, true, 'You already asked for a cookie.'); |
59 | | - return; |
60 | | - } |
| 56 | + try { |
| 57 | + if (NEURO.waitingForCookie) { |
| 58 | + logOutput('INFO', 'Already waiting for a cookie'); |
| 59 | + NEURO.client?.sendActionResult(actionData.id, true, 'You already asked for a cookie.'); |
| 60 | + return; |
| 61 | + } |
61 | 62 |
|
62 | | - const permission = getPermissionLevel(PERMISSIONS.requestCookies); |
| 63 | + const permission = getPermissionLevel(PERMISSIONS.requestCookies); |
63 | 64 |
|
64 | | - switch (permission) { |
65 | | - case PermissionLevel.OFF: |
66 | | - logOutput('WARNING', 'Neuro attempted to request a cookie, but permission is disabled'); |
67 | | - NEURO.client?.sendActionResult(actionData.id, true, 'Permission to request cookies is disabled.'); |
68 | | - break; |
69 | | - case PermissionLevel.COPILOT: |
70 | | - NEURO.waitingForCookie = true; |
71 | | - vscode.window.showInformationMessage( |
72 | | - `${NEURO.currentController} is asking for a${actionData.params?.flavor ? ' ' + actionData.params.flavor : ''} cookie.`, |
73 | | - 'Give', |
74 | | - 'Deny', |
75 | | - ).then((value) => { |
76 | | - if (value === 'Give') { |
77 | | - giveCookie(true, actionData.params?.flavor); |
78 | | - } else if (value === 'Deny' || value === undefined) { |
79 | | - denyCookie(); |
| 65 | + switch (permission) { |
| 66 | + case PermissionLevel.OFF: |
| 67 | + logOutput('WARNING', 'Neuro attempted to request a cookie, but permission is disabled'); |
| 68 | + NEURO.client?.sendActionResult(actionData.id, true, 'Permission to request cookies is disabled.'); |
| 69 | + break; |
| 70 | + case PermissionLevel.COPILOT: |
| 71 | + NEURO.waitingForCookie = true; |
| 72 | + vscode.window.showInformationMessage( |
| 73 | + `${NEURO.currentController} is asking for a${actionData.params?.flavor ? ' ' + actionData.params.flavor : ''} cookie.`, |
| 74 | + 'Give', |
| 75 | + 'Deny', |
| 76 | + ).then((value) => { |
| 77 | + if (value === 'Give') { |
| 78 | + giveCookie(true, actionData.params?.flavor); |
| 79 | + } else if (value === 'Deny' || value === undefined) { |
| 80 | + denyCookie(); |
| 81 | + } |
| 82 | + NEURO.waitingForCookie = false; |
| 83 | + }); |
| 84 | + NEURO.client?.sendActionResult(actionData.id, true, 'Vedal has been asked for a cookie.'); |
| 85 | + break; |
| 86 | + case PermissionLevel.AUTOPILOT: |
| 87 | + if (!actionData.params?.flavor) { |
| 88 | + NEURO.client?.sendActionResult(actionData.id, false, 'You need to specify a flavor!'); |
| 89 | + break; |
80 | 90 | } |
81 | | - NEURO.waitingForCookie = false; |
82 | | - }); |
83 | | - NEURO.client?.sendActionResult(actionData.id, true, 'Vedal has been asked for a cookie.'); |
84 | | - break; |
85 | | - case PermissionLevel.AUTOPILOT: |
86 | | - if (!actionData.params?.flavor) { |
87 | | - NEURO.client?.sendActionResult(actionData.id, false, 'You need to specify a flavor!'); |
| 91 | + logOutput('INFO', `Neuro grabbed a ${actionData.params?.flavor} cookie.`); |
| 92 | + NEURO.client?.sendActionResult(actionData.id, true, `You grabbed a ${actionData.params?.flavor} cookie!`); |
88 | 93 | break; |
89 | | - } |
90 | | - logOutput('INFO', `Neuro grabbed a ${actionData.params?.flavor} cookie.`); |
91 | | - NEURO.client?.sendActionResult(actionData.id, true, `You grabbed a ${actionData.params?.flavor} cookie!`); |
92 | | - break; |
| 94 | + } |
| 95 | + } catch (erm) { |
| 96 | + const actionName = actionData.name; |
| 97 | + notifyOnCaughtException(actionName, erm); |
| 98 | + NEURO.client?.sendActionResult(actionData.id, true, `An error occured while executing the action "${actionName}". You may retry if you like, but it may be better to ask Vedal to check what's up.`); |
| 99 | + return; |
93 | 100 | } |
94 | 101 | } |
95 | 102 | }); |
|
0 commit comments