-
Notifications
You must be signed in to change notification settings - Fork 2
JSON response error handling + abort timeout handling #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ export const useExecutionPolling = (executionId: string | undefined | null, poll | |||||||||||||||||||||||
operation: 'Code execution state', | ||||||||||||||||||||||||
url: `/apps/acm/api/queue-code.json?executionId=${executionId}`, | ||||||||||||||||||||||||
method: 'get', | ||||||||||||||||||||||||
quiet: true, | ||||||||||||||||||||||||
timeout: intervalToTimeout(pollInterval), | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
const queuedExecution = response.data.data.executions.find((e: Execution) => e.id === executionId)!; | ||||||||||||||||||||||||
|
@@ -65,15 +66,20 @@ export const pollExecutionPending = async (executionId: string, pollInterval: nu | |||||||||||||||||||||||
let queuedExecution: Execution | null = null; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
while (queuedExecution === null || isExecutionPending(queuedExecution.status)) { | ||||||||||||||||||||||||
const response = await apiRequest<QueueOutput>({ | ||||||||||||||||||||||||
operation: 'Code execution state', | ||||||||||||||||||||||||
url: `/apps/acm/api/queue-code.json?executionId=${executionId}`, | ||||||||||||||||||||||||
method: 'get', | ||||||||||||||||||||||||
timeout: intervalToTimeout(pollInterval), | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
queuedExecution = response.data.data.executions[0]!; | ||||||||||||||||||||||||
try { | ||||||||||||||||||||||||
const response = await apiRequest<QueueOutput>({ | ||||||||||||||||||||||||
operation: 'Code execution pending state', | ||||||||||||||||||||||||
url: `/apps/acm/api/queue-code.json?executionId=${executionId}`, | ||||||||||||||||||||||||
method: 'get', | ||||||||||||||||||||||||
quiet: true, | ||||||||||||||||||||||||
timeout: intervalToTimeout(pollInterval), | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
queuedExecution = response.data.data.executions[0]!; | ||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||
console.warn('Code execution pending state unknown:', error); | ||||||||||||||||||||||||
Comment on lines
+77
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The setTimeout is called regardless of whether the API request succeeded or failed. This means the function will continue polling indefinitely even after errors, potentially creating an infinite loop if the API consistently fails.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's expected; temporary fails are possible |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
await new Promise((resolve) => setTimeout(resolve, pollInterval)); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return queuedExecution; | ||||||||||||||||||||||||
return queuedExecution!; | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The non-null assertion operator (!) is unsafe here. If an error occurs in the try-catch block and queuedExecution remains null, this will cause a runtime error. Consider returning null or throwing a specific error instead.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change from streaming to buffered JSON responses is a breaking change in behavior. The old streaming method consumed less memory, and switching all responses to buffered mode could impact performance for large responses without providing a migration path.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but improves error handling; now when something breaks the malformed JSON is output