Skip to content

Commit 3a48120

Browse files
committed
Replace unsafe any-typed catch variables with unknown and normalize error message extraction across the editor extension
- instead of assigning 'any' to errors, use such approach [Pasted text] └── apps ├── browser │ ├── create-zip-archives.ts │ └── src │ ├── background │ │ └── clear-chat-init-data.ts │ ├── content-scripts │ │ └── send-prompt-content-script │ │ └── utils │ │ └── add-apply-response-button.ts │ └── views │ └── popup │ └── use-firefox-containers.ts ├── editor │ └── src │ ├── commands │ │ ├── apply-response-command │ │ │ ├── response-processor │ │ │ │ └── handlers │ │ │ │ ├── diff-handler.ts │ │ │ │ ├── fast-replace-handler.ts │ │ │ │ ├── restore-preview-handler.ts │ │ │ │ ├── search-replace-handler.ts │ │ │ │ └── truncated-handler.ts │ │ │ └── utils │ │ │ ├── file-operations │ │ │ │ ├── create-file-if-needed.ts │ │ │ │ ├── handle-deleted-file-item.ts │ │ │ │ ├── relocate-file.ts │ │ │ │ ├── remove-directory-if-empty.ts │ │ │ │ └── undo-files.ts │ │ │ ├── preview │ │ │ │ ├── build-history-files.ts │ │ │ │ ├── file-preparer.ts │ │ │ │ └── vscode-ui.ts │ │ │ ├── preview-handler.ts │ │ │ └── tab-group-manager.ts │ │ ├── copy-markdown-command.ts │ │ ├── copy-merge-commit-details-command.ts │ │ ├── delete-command.ts │ │ ├── generate-commit-message-commands │ │ │ ├── actions │ │ │ │ └── run-generate-action.ts │ │ │ └── utils │ │ │ └── generate-commit-message-with-api.ts │ │ ├── history-command │ │ │ └── actions │ │ │ ├── clear-all-checkpoints.ts │ │ │ ├── delete-checkpoint-with-undo.ts │ │ │ └── restore-checkpoint.ts │ │ ├── new-file-command.ts │ │ ├── new-folder-command.ts │ │ ├── rename-command.ts │ │ ├── restore-file-selection-command │ │ │ └── actions │ │ │ ├── restore-from-json-file.ts │ │ │ └── restore-from-workspace-state.ts │ │ ├── search-files-commands │ │ │ └── utils │ │ │ └── get-target-folder-path.ts │ │ ├── select-clipboard-paths-command.ts │ │ ├── select-definition-file-command.ts │ │ ├── select-files-of-commit-command.ts │ │ ├── select-imported-files-commands │ │ │ └── utils │ │ │ └── prompt-for-imported-files.ts │ │ ├── select-modified-files-command.ts │ │ ├── select-referencing-files-commands │ │ │ ├── select-referencing-files-commands.ts │ │ │ └── utils │ │ │ └── prompt-for-referencing-files.ts │ │ ├── select-workspace-file-command.ts │ │ └── set-ranges-command.ts │ ├── context │ │ ├── context-initialization.ts │ │ └── providers │ │ ├── open-editors │ │ │ └── open-editors-provider.ts │ │ └── workspace │ │ ├── modules │ │ │ └── token-calculator.ts │ │ └── workspace-provider.ts │ ├── features │ │ ├── checkpoints │ │ │ ├── actions │ │ │ │ ├── create-checkpoint.ts │ │ │ │ ├── delete-checkpoint.ts │ │ │ │ └── get-checkpoints.ts │ │ │ └── utils │ │ │ └── git-utils.ts │ │ ├── context-restoration │ │ │ └── utils │ │ │ ├── context-file-utils.ts │ │ │ ├── global-storage-utils.ts │ │ │ ├── path-utils.ts │ │ │ ├── resolve-glob-patterns.ts │ │ │ └── source-selector.ts │ │ └── search-files │ │ ├── search-files.ts │ │ └── utils │ │ ├── search-files-by-intelligent.ts │ │ ├── search-files-by-keywords.ts │ │ ├── search-files-by-phrase.ts │ │ └── show-search-results-quick-pick.ts │ ├── migrations │ │ ├── migrate-clear-all-checkpoints.ts │ │ ├── migrate-commit-message-details-filename.ts │ │ ├── migrate-configurations-to-api-configurations.ts │ │ ├── migrate-edit-context-to-edit-files-system-instructions.ts │ │ ├── migrate-model-providers-to-providers.ts │ │ ├── migrate-prompt-templates-suffixes.ts │ │ ├── migrate-prompt-templates-to-templates.ts │ │ └── migrate-settings-keys-to-chatbots-and-models.ts │ ├── services │ │ ├── git-discard-file-watcher.ts │ │ ├── model-fetcher.ts │ │ ├── prompt-view-api-calls-manager.ts │ │ ├── providers-manager.ts │ │ └── websocket-manager.ts │ ├── utils │ │ ├── changes-integration │ │ │ └── diff-processor │ │ │ └── test-cases │ │ │ ├── generic-3 │ │ │ │ ├── diff.txt │ │ │ │ ├── expected.txt │ │ │ │ └── original.txt │ │ │ └── generic-4 │ │ │ ├── diff.txt │ │ │ ├── expected.txt │ │ │ └── original.txt │ │ ├── commit-message-details.ts │ │ ├── files-collector.ts │ │ ├── send-llm-message.ts │ │ └── tasks-utils.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-go-to-file.ts │ │ │ │ ├── handle-hash-sign-quick-pick │ │ │ │ │ └── symbols │ │ │ │ │ ├── changes-symbol.ts │ │ │ │ │ ├── commit-symbol.ts │ │ │ │ │ ├── saved-context-symbol.ts │ │ │ │ │ └── skill-symbol.ts │ │ │ │ ├── handle-make-api-call.ts │ │ │ │ ├── handle-open-file-and-select.ts │ │ │ │ ├── handle-open-prompt-image.ts │ │ │ │ ├── handle-open-prompt-pasted-text.ts │ │ │ │ ├── handle-paste-url.ts │ │ │ │ ├── handle-patch-repair.ts │ │ │ │ ├── handle-pick-api-reasoning-effort.ts │ │ │ │ ├── handle-preview-changes-symbol.ts │ │ │ │ ├── handle-preview-commit-symbol.ts │ │ │ │ ├── handle-preview-generated-code.ts │ │ │ │ ├── handle-preview-skill-symbol.ts │ │ │ │ ├── handle-save-prompt-image.ts │ │ │ │ ├── handle-save-prompt-pasted-text.ts │ │ │ │ ├── handle-show-diff.ts │ │ │ │ ├── handle-undo.ts │ │ │ │ ├── handle-voice-input.ts │ │ │ │ └── utils │ │ │ │ └── patch-repair-utils.ts │ │ │ ├── prompt-view-provider.ts │ │ │ └── utils │ │ │ ├── preview-text-in-temp-file.ts │ │ │ ├── symbols │ │ │ │ ├── git │ │ │ │ │ └── replace-git-symbols.ts │ │ │ │ ├── image │ │ │ │ │ └── replace-image-symbol.ts │ │ │ │ ├── pasted-text │ │ │ │ │ └── replace-pasted-text-symbol.ts │ │ │ │ ├── saved-context │ │ │ │ │ └── replace-saved-context-symbol.ts │ │ │ │ └── website │ │ │ │ └── replace-website-symbol.ts │ │ │ └── website-fetcher.ts │ │ └── frontend │ │ └── hooks │ │ └── use-recent-donations.ts │ ├── settings │ │ └── backend │ │ └── message-handlers │ │ └── handle-pick-api-reasoning-effort.ts │ └── shared │ └── actions │ ├── api │ │ ├── create │ │ │ └── interactions │ │ │ ├── initial-select-model.ts │ │ │ └── verify-reasoning-effort.ts │ │ └── update │ │ └── interactions │ │ └── edit-model-for-api-config.ts │ └── web │ ├── delete.ts │ └── pick-model.ts └── old-website └── copy-readme.js
1 parent 56eabd6 commit 3a48120

29 files changed

Lines changed: 127 additions & 93 deletions

‎apps/editor/src/commands/apply-response-command/response-processor/handlers/diff-handler.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,14 @@ const handle_new_file_patch = async (
371371
await fs.promises.writeFile(safe_path, new_content, 'utf8')
372372

373373
return { success: true, original_states }
374-
} catch (error: any) {
374+
} catch (error) {
375375
Logger.error({
376376
function_name: 'handle_new_file_patch',
377377
message: 'Failed to create new file from patch.',
378-
data: { error: error.message, file_path }
378+
data: {
379+
error: error instanceof Error ? error.message : String(error),
380+
file_path
381+
}
379382
})
380383
// Attempt cleanup if file was created but something went wrong.
381384
if (fs.existsSync(safe_path)) await fs.promises.unlink(safe_path)
@@ -449,11 +452,14 @@ const handle_deleted_file_patch = async (
449452
}
450453

451454
return { success: true, original_states }
452-
} catch (error: any) {
455+
} catch (error) {
453456
Logger.error({
454457
function_name: 'handle_deleted_file_patch',
455458
message: 'Failed to delete file from patch.',
456-
data: { error: error.message, file_path }
459+
data: {
460+
error: error instanceof Error ? error.message : String(error),
461+
file_path
462+
}
457463
})
458464
return { success: false, original_states }
459465
}
@@ -669,11 +675,14 @@ export const apply_git_patch = async (
669675
// All methods failed, throw the last logged error to be handled by the outer catch
670676
throw last_error
671677
}
672-
} catch (error: any) {
678+
} catch (error) {
673679
// This outer catch handles setup errors and final application failures
674680
await reopen_closed_files(closed_files)
675681

676-
const has_rejects = error?.message?.includes('.rej')
682+
const has_rejects =
683+
error instanceof Error
684+
? error.message.includes('.rej')
685+
: String(error).includes('.rej')
677686
if (has_rejects) {
678687
const file_paths = extract_file_paths_from_patch(patch_content)
679688
await process_modified_files(file_paths, workspace_path)

‎apps/editor/src/commands/apply-response-command/response-processor/handlers/fast-replace-handler.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const handle_fast_replace = async (params: {
166166
})
167167

168168
continue
169-
} catch (error: any) {
169+
} catch (error) {
170170
Logger.error({
171171
function_name: 'handle_fast_replace',
172172
message: 'Error handling rename',
@@ -175,7 +175,7 @@ export const handle_fast_replace = async (params: {
175175
vscode.window.showErrorMessage(
176176
t('command.apply-response-command.error.processing-file', {
177177
path: file.file_path,
178-
msg: error.message || 'Unknown error'
178+
msg: error instanceof Error ? error.message : String(error)
179179
})
180180
)
181181
continue
@@ -279,7 +279,7 @@ export const handle_fast_replace = async (params: {
279279
continue
280280
}
281281
}
282-
} catch (error: any) {
282+
} catch (error) {
283283
Logger.error({
284284
function_name: 'handle_fast_replace',
285285
message: 'Error processing file during replacement',
@@ -288,7 +288,7 @@ export const handle_fast_replace = async (params: {
288288
vscode.window.showErrorMessage(
289289
t('command.apply-response-command.error.processing-file', {
290290
path: file.file_path,
291-
msg: error.message || 'Unknown error'
291+
msg: error instanceof Error ? error.message : String(error)
292292
})
293293
)
294294
continue
@@ -301,7 +301,7 @@ export const handle_fast_replace = async (params: {
301301
data: { file_count: safe_files.length }
302302
})
303303
return { success: true, original_states }
304-
} catch (error: any) {
304+
} catch (error) {
305305
Logger.error({
306306
function_name: 'handle_fast_replace',
307307
message: 'Error during direct file replacement',
@@ -310,7 +310,7 @@ export const handle_fast_replace = async (params: {
310310
console.error('Error during direct file replacement:', error)
311311
vscode.window.showErrorMessage(
312312
t('command.apply-response-command.error.replacing-files', {
313-
msg: error.message || 'Unknown error'
313+
msg: error instanceof Error ? error.message : String(error)
314314
})
315315
)
316316
return { success: false }

‎apps/editor/src/commands/apply-response-command/response-processor/handlers/search-replace-handler.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const handle_search_replace = async (params: {
173173
message: 'Applied search replace edit to file',
174174
data: safe_path
175175
})
176-
} catch (error: any) {
176+
} catch (error) {
177177
Logger.error({
178178
function_name: 'handle_search_replace',
179179
message: 'Failed to apply search replace edit',
@@ -243,7 +243,7 @@ export const handle_search_replace = async (params: {
243243
ai_content: file.content,
244244
proposed_content: final_content
245245
})
246-
} catch (error: any) {
246+
} catch (error) {
247247
Logger.error({
248248
function_name: 'handle_search_replace',
249249
message: 'Error replacing file content (fallback)',
@@ -255,15 +255,15 @@ export const handle_search_replace = async (params: {
255255
}
256256

257257
return { success: true, original_states, failed_files }
258-
} catch (error: any) {
258+
} catch (error) {
259259
Logger.error({
260260
function_name: 'handle_search_replace',
261261
message: 'Error during search replace edit',
262262
data: error
263263
})
264264
vscode.window.showErrorMessage(
265265
t('command.apply-response-command.error.applying-changes', {
266-
msg: error.message || 'Unknown error'
266+
msg: error instanceof Error ? error.message : String(error)
267267
})
268268
)
269269
return { success: false }

‎apps/editor/src/commands/apply-response-command/response-processor/handlers/truncated-handler.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ export const handle_truncated_edit = async (params: {
136136
data: safe_path
137137
})
138138
continue
139-
} catch (error: any) {
139+
} catch (error) {
140140
Logger.error({
141141
function_name: 'handle_truncated_edit',
142142
message: 'Failed to process truncated file for rename',
143-
data: { error: error.message, file_path: safe_path }
143+
data: {
144+
error: error instanceof Error ? error.message : String(error),
145+
file_path: safe_path
146+
}
144147
})
145148
failed_files.push(file)
146149
continue
@@ -166,11 +169,14 @@ export const handle_truncated_edit = async (params: {
166169
ai_content: file.content,
167170
proposed_content: new_content
168171
})
169-
} catch (error: any) {
172+
} catch (error) {
170173
Logger.error({
171174
function_name: 'handle_truncated_edit',
172175
message: 'Failed to create new file',
173-
data: { error: error.message, file_path: safe_path }
176+
data: {
177+
error: error instanceof Error ? error.message : String(error),
178+
file_path: safe_path
179+
}
174180
})
175181
failed_files.push(file)
176182
}
@@ -205,11 +211,14 @@ export const handle_truncated_edit = async (params: {
205211
message: 'Applied truncated edit',
206212
data: safe_path
207213
})
208-
} catch (error: any) {
214+
} catch (error) {
209215
Logger.error({
210216
function_name: 'handle_truncated_edit',
211217
message: 'Failed to process truncated file',
212-
data: { error: error.message, file_path: safe_path }
218+
data: {
219+
error: error instanceof Error ? error.message : String(error),
220+
file_path: safe_path
221+
}
213222
})
214223
failed_files.push(file)
215224
}

‎apps/editor/src/commands/apply-response-command/utils/file-operations/handle-deleted-file-item.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ export const handle_deleted_file_item = async (params: {
4949
message: 'File deleted',
5050
data: params.safe_path
5151
})
52-
} catch (error: any) {
52+
} catch (error) {
5353
Logger.error({
5454
function_name: params.function_name,
5555
message: 'Failed to delete file',
56-
data: { error: error.message || error, file_path: params.safe_path }
56+
data: {
57+
error: error instanceof Error ? error.message : String(error),
58+
file_path: params.safe_path
59+
}
5760
})
5861
return { success: false }
5962
}

‎apps/editor/src/commands/apply-response-command/utils/file-operations/undo-files.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export const undo_files = async (params: {
234234
message: 'Changes successfully undone.'
235235
})
236236
return true
237-
} catch (error: any) {
237+
} catch (error) {
238238
Logger.error({
239239
function_name: 'undo_files',
240240
message: 'Error during undo',
@@ -243,7 +243,7 @@ export const undo_files = async (params: {
243243
console.error('Error during undo:', error)
244244
vscode.window.showErrorMessage(
245245
t('command.apply-response-command.error.failed-to-undo', {
246-
msg: error.message || 'Unknown error'
246+
msg: error instanceof Error ? error.message : String(error)
247247
})
248248
)
249249
return false

‎apps/editor/src/commands/copy-markdown-command.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const copy_markdown_commands = (
2424
})
2525
other_files = collected.other_files
2626
recent_files = collected.recent_files
27-
} catch (error: any) {
27+
} catch (error) {
2828
Logger.error({
2929
function_name: 'copy_markdown_command',
3030
message: 'Error collecting files',
@@ -110,11 +110,11 @@ export const copy_markdown_commands = (
110110
filepath: display_path,
111111
content
112112
})
113-
} catch (error: any) {
113+
} catch (error) {
114114
vscode.window.showErrorMessage(
115115
t('command.copy-markdown-command.error.reading-file', {
116116
filePath: file_path,
117-
message: error.message
117+
message: error instanceof Error ? error.message : String(error)
118118
})
119119
)
120120
}

‎apps/editor/src/commands/generate-commit-message-commands/actions/run-generate-action.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,17 @@ export const run_generate_action = async (params: {
490490
message: final_api_prompt!
491491
})
492492
action_completed = true
493-
} catch (error: any) {
493+
} catch (error) {
494+
const error_msg =
495+
error instanceof Error ? error.message : String(error)
494496
if (
495497
axios.isCancel(error) ||
496-
error?.message == 'Operation cancelled by user'
498+
error_msg == 'Operation cancelled by user'
497499
) {
498500
show_quick_pick = true
499501
continue
500502
} else {
501-
if (error?.message == 'API request returned an empty response') {
503+
if (error_msg == 'API request returned an empty response') {
502504
vscode.window.showErrorMessage(
503505
t(
504506
'command.generate-commit-message-command.error.empty-response'

‎apps/editor/src/commands/history-command/actions/delete-checkpoint-with-undo.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export const delete_checkpoint_with_undo = async (params: {
4646
await vscode.workspace.fs.delete(vscode.Uri.file(checkpoint_path), {
4747
recursive: true
4848
})
49-
} catch (error: any) {
49+
} catch (error) {
5050
vscode.window.showWarningMessage(
5151
t('command.history-command.warning.could-not-delete', {
52-
error: error.message
52+
error: error instanceof Error ? error.message : String(error)
5353
})
5454
)
5555
}

‎apps/editor/src/commands/history-command/actions/restore-checkpoint.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export const restore_checkpoint = async (params: {
142142
temp_checkpoint
143143
)
144144
}
145-
} catch (err: any) {
145+
} catch (err) {
146146
vscode.window.showErrorMessage(
147147
t('command.history-command.error.create-temp-failed', {
148-
error: err.message
148+
error: err instanceof Error ? err.message : String(err)
149149
})
150150
)
151151
await params.extension_context.workspaceState.update(
@@ -518,14 +518,14 @@ export const restore_checkpoint = async (params: {
518518
})
519519
}
520520
}
521-
} catch (err: any) {
521+
} catch (err) {
522522
await params.extension_context.workspaceState.update(
523523
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY,
524524
undefined
525525
)
526526
vscode.window.showErrorMessage(
527527
t('command.history-command.error.restore-failed', {
528-
error: err.message
528+
error: err instanceof Error ? err.message : String(err)
529529
})
530530
)
531531
if (temp_checkpoint) {

0 commit comments

Comments
 (0)