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

Synchronous Swift methods cannot throw errors #156

Closed
mrousavy opened this issue Sep 24, 2024 · 1 comment · Fixed by #430
Closed

Synchronous Swift methods cannot throw errors #156

mrousavy opened this issue Sep 24, 2024 · 1 comment · Fixed by #430
Labels
swift Issue regarding the Swift part of Nitro/Nitrogen

Comments

@mrousavy
Copy link
Owner

In a synchronous method inside of a Swift HybridObject, you cannot throw any errors because they are not propagated upwards to C++.

The previous workaround used result types (.success(value) or .failure(error)) instead of exceptions, but those will be caught and wrapped anyways. This didn't work because of a Swift compiler bug where arrays/generics couldn't be used inside enums, so we could only support primitives.

A workaround would be to just return a Promise<..>, then you can throw inside there which will be a promise rejection.

@mrousavy mrousavy added the swift Issue regarding the Swift part of Nitro/Nitrogen label Sep 24, 2024
@mrousavy
Copy link
Owner Author

created a PR to finally fix this: #430

was definitely not easy lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift Issue regarding the Swift part of Nitro/Nitrogen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant