Skip to content
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

feat: Implement Swift errors 🥳 #430

Merged
merged 21 commits into from
Dec 18, 2024
Merged

feat: Implement Swift errors 🥳 #430

merged 21 commits into from
Dec 18, 2024

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Dec 18, 2024

Finally implements errors for synchronous Swift functions.

Every Swift function is now wrapped with a Result<T> type that is either T (hasValue()) or std::exception_ptr (hasError()).

This adds a tiny bit of runtime overhead, but at least now we can throw errors that can actually be caught in JS without crashing the app.

I hope in a future version of Swift, Swift errors can actually be caught in C++ so that we can remove this result type wrapping and instead use normal try/catch flows....

Copy link

vercel bot commented Dec 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nitro-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 3:41pm

@mrousavy mrousavy merged commit 5b3fa6c into main Dec 18, 2024
16 checks passed
(
await it(async () => await testObject.funcThatThrowsBeforePromise())
).didThrow(
`Error: ${testObject.name}.funcThatThrowsBeforePromise(...): This function will only work after sacrificing eight lambs!`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

@grabbou
Copy link
Contributor

grabbou commented Dec 20, 2024

Awesome, very excited to try this out! Just upgrading the library to 0.20.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synchronous Swift methods cannot throw errors
3 participants