fix: catch errors thrown by onSuccess callback to prevent stuck loading state#143
Draft
behnam-oneschema wants to merge 1 commit into
Draft
fix: catch errors thrown by onSuccess callback to prevent stuck loading state#143behnam-oneschema wants to merge 1 commit into
behnam-oneschema wants to merge 1 commit into
Conversation
…ng state Closes #136 When an onSuccess callback throws (sync or async), the importer could get stuck in a loading state because cleanup code (resume-token removal, autoClose, onRequestClose) never executed. Changes: - importer.ts: wrap success event emission in try/catch so cleanup always runs; surface caught errors via the error event - OneSchemaImporter.tsx (React): wrap onSuccess call to catch both sync throws and async rejections, forward to onError, and always call onRequestClose Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Original prompt from Behnam 🧑💻
|
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #136.
When an
onSuccesscallback throws (synchronously or via an async rejection), the importer gets stuck in a loading state because cleanup code never executes. This PR adds error handling at two layers:packages/importer/src/importer.ts— Wrapsthis.emit("success", ...)in a try/catch inside the"complete"message handler. This ensures resume-token removal andautoClosealways run regardless of listener errors. Caught errors are surfaced via the existingerrorevent withErrorseverity (notFatal, since the data import itself succeeded).packages/importer-react/src/OneSchemaImporter.tsx— Wraps theonSuccess?.(data)call to catch both synchronous throws and asynchronous Promise rejections. Errors are forwarded toonError.onRequestClose()is now always called.Tasks
#136
Review & Testing Checklist for Human
onSuccesshandlers,onRequestClosefires synchronously (immediately), whileonErrorfires asynchronously (when the Promise rejects). Verify this ordering is acceptable for consumers — the importer will close beforeonErroris called.onErroritself throwing: If the consumer'sonErrorhandler throws, that error is not caught. Decide if this is acceptable or if it needs a guard too.filefeeds.ts,OneSchemaFileFeeds.tsx) has similar emit/callback patterns but is not patched here. Confirm this is the desired scope.onSuccessthat throws synchronously and one that returns a rejected Promise. Confirm the importer closes properly andonErroris called in both cases.Notes
onSuccessprop is typed as(data: any) => void, but at runtime consumers commonly pass async functions. The fix captures the return value and checksinstanceof Promiseto handle this case.Error(notFatal) since the data import completed successfully on the backend — only the consumer's callback failed.Link to Devin session: https://app.devin.ai/sessions/5f7e446f2a86441b8b4eb120916536af
Requested by: @behnam-oneschema