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

Add JSError.stack, add Error conformance #48

Merged
merged 3 commits into from
Sep 15, 2020
Merged

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Sep 14, 2020

While the stack property is non-standard, it's supported in all popular browser engines and Node.js.

Unfortunately, because stack value will be different on every machine that executes it, I'm not sure how to write a good test for it, so it currently doesn't have any tests.

Also, JSError now conforms to Error. The main reasoning is that the Publisher protocol in Combine requires Error conformance on its Failure type. I think in the future it would make sense to make JSPromise compatible with Combine, so it would be great if one could propagate errors produced by JSPromise to other publishers/subscribers.

Again, JSPromise will be implemented in a separate PR.

@MaxDesiatov MaxDesiatov requested a review from a team September 14, 2020 08:50
@j-f1
Copy link
Member

j-f1 commented Sep 14, 2020

You could test that the stack is a non-empty string.

@MaxDesiatov
Copy link
Contributor Author

Great point, I've added the check to the test.

@@ -13,6 +13,10 @@ public final class JSError {
public var name: String {
ref.name.string!
}

public var stack: String {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more safe if non-standard field is exposed as String?. For example, a new JS engine may not implement this feature.

@MaxDesiatov MaxDesiatov merged commit 3220b3c into master Sep 15, 2020
@MaxDesiatov MaxDesiatov deleted the jserror-stack branch September 15, 2020 08:46
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.

3 participants