Skip to content

Commit 630485c

Browse files
committed
Fix function name inconsistencies and improve error handling with retry logic for API requests
1 parent 4080031 commit 630485c

5 files changed

Lines changed: 275 additions & 286 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/handlers/active-editor-intelligent-update-handler.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const handle_active_editor_intelligent_update = async (params: {
3333
dictionary.error_message.CANNOT_PROCESS_MULTIPLE_FILES_WITHOUT_WORKSPACE
3434
)
3535
Logger.warn({
36-
function_name: 'handle_intelligent_update',
36+
function_name: 'handle_active_editor_intelligent_update',
3737
message: 'No workspace folder open.'
3838
})
3939
return null
@@ -53,12 +53,12 @@ export const handle_active_editor_intelligent_update = async (params: {
5353
(item): item is FileItem => item.type == 'file'
5454
)
5555

56-
if (files.length === 0) {
56+
if (files.length == 0) {
5757
vscode.window.showErrorMessage(
5858
dictionary.error_message.NO_VALID_FILE_CONTENT_IN_CLIPBOARD
5959
)
6060
Logger.warn({
61-
function_name: 'handle_intelligent_update',
61+
function_name: 'handle_active_editor_intelligent_update',
6262
message: 'No valid file content found.'
6363
})
6464
return null
@@ -80,7 +80,7 @@ export const handle_active_editor_intelligent_update = async (params: {
8080
dictionary.error_message.INVALID_FILE_PATH_TRAVERSAL(file_item.file_path)
8181
)
8282
Logger.error({
83-
function_name: 'handle_intelligent_update',
83+
function_name: 'handle_active_editor_intelligent_update',
8484
message: 'Invalid file path',
8585
data: file_item.file_path
8686
})

‎apps/editor/src/commands/code-completion-commands.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const get_code_completion_config = async (
228228
if (panel_provider) {
229229
panel_provider.send_message({
230230
command: 'SELECTED_CONFIGURATION_CHANGED',
231-
mode: 'code-at-cursor',
231+
prompt_type: 'code-at-cursor',
232232
id: selected.id
233233
})
234234
}
@@ -528,7 +528,7 @@ const perform_code_completion = async (params: {
528528
}
529529
} catch (err: any) {
530530
Logger.error({
531-
function_name: 'perform_fim_completion',
531+
function_name: 'perform_code_completion',
532532
message: 'Completion error',
533533
data: err
534534
})

‎apps/editor/src/utils/intelligent-update-utils.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ export const process_file = async (params: {
178178

179179
apply_reasoning_effort(body, params.provider, params.reasoning_effort)
180180

181+
const MAX_ATTEMPTS = 3
181182
let attempt = 0
182-
// eslint-disable-next-line no-constant-condition
183-
while (true) {
183+
while (attempt < MAX_ATTEMPTS) {
184184
attempt++
185185
try {
186186
const result = await make_api_request({
@@ -189,7 +189,8 @@ export const process_file = async (params: {
189189
body,
190190
cancellation_token: params.cancel_token,
191191
on_chunk: params.on_chunk,
192-
on_thinking_chunk: params.on_thinking_chunk
192+
on_thinking_chunk: params.on_thinking_chunk,
193+
rethrow_error: true
193194
})
194195

195196
const refactored_content = result?.response
@@ -224,6 +225,21 @@ export const process_file = async (params: {
224225
throw error
225226
}
226227

228+
const is_retryable_error =
229+
(axios.isAxiosError(error) &&
230+
(error.response?.status == 429 ||
231+
(error.response?.status && error.response.status >= 500))) ||
232+
error.name == 'StreamAbortError'
233+
234+
if (!is_retryable_error) {
235+
Logger.error({
236+
function_name: 'process_file',
237+
message: `Refactoring error (attempt ${attempt}) - not retrying`,
238+
data: { error, file_path: params.file_path }
239+
})
240+
throw error
241+
}
242+
227243
Logger.error({
228244
function_name: 'process_file',
229245
message: `Refactoring error (attempt ${attempt})`,
@@ -233,8 +249,15 @@ export const process_file = async (params: {
233249
`Refactoring error for ${params.file_path} (attempt ${attempt}):`,
234250
error
235251
)
252+
253+
if (attempt >= MAX_ATTEMPTS) {
254+
throw error
255+
}
256+
236257
params.on_retry?.(attempt, error)
237-
await new Promise((resolve) => setTimeout(resolve, 5000))
258+
await new Promise((resolve) => setTimeout(resolve, 3000))
259+
params.on_retry_attempt?.()
238260
}
239261
}
262+
throw new Error('Processing file failed after maximum attempts')
240263
}

0 commit comments

Comments
 (0)