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

Feature request: support error cause in expect #34

Open
Jack-Works opened this issue Aug 3, 2021 · 3 comments
Open

Feature request: support error cause in expect #34

Jack-Works opened this issue Aug 3, 2021 · 3 comments

Comments

@Jack-Works
Copy link
Contributor

class Err {
    // ...
    expect(msg: string) {
        throw new Error(msg, { cause: this.val })
    }
}
@jstasiak
Copy link
Contributor

I think I'm asking about a similar thing here: #48

@Jack-Works do you think the pattern in your opening post is the best way to resolve this?

@Jack-Works
Copy link
Contributor Author

Error cause is a new JavaScript proposal to bring another Error in the current Error object.

image

@jstasiak
Copy link
Contributor

Thanks for the explanation, I like it. I'll add this to https://github.com/lune-climate/ts-results-es

jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 29, 2022
We need TypeScript 4.6+ to be able to construct Error objects with the
cause property[1]. The property is useful to chain errors and, on the
catching side, to see what error caused the error we just caught.

I want to have this in place to implement [3] which satisfies a need we
ourselves have[4].

tslib upgraded in lockstep because otherwise we get

    FAIL  test/result.test.ts
      ● Test suite failed to run

        test/result.test.ts:121:29 - error TS2807: This syntax requires an imported helper named '__spreadArray' with 3 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'.

        121     const all4 = Result.all(...([] as Result<string, number>[]));
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error
[2] microsoft/TypeScript#45167
[3] vultix#34
[4] vultix#48
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 29, 2022
I want to have this in place to implement [1] which satisfies a need we
ourselves have[2]. This is needed because the cause property is only
availble in the es2022 TS profile[3].

[1] vultix#34
[2] vultix#48
[3] microsoft/TypeScript#47020
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 29, 2022
This is useful to get access to the "underlying" error in global
exception-handling code for example.

Feature requested in [1] and I had a question about something similar as
well[2].

[1] vultix#34
[2] vultix#48
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 29, 2022
We need TypeScript 4.6+ to be able to construct Error objects with the
cause property[1]. The property is useful to chain errors and, on the
catching side, to see what error caused the error we just caught.

I want to have this in place to implement [3] which satisfies a need we
ourselves have[4].

tslib upgraded in lockstep because otherwise we get

    FAIL  test/result.test.ts
      ● Test suite failed to run

        test/result.test.ts:121:29 - error TS2807: This syntax requires an imported helper named '__spreadArray' with 3 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'.

        121     const all4 = Result.all(...([] as Result<string, number>[]));
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error
[2] microsoft/TypeScript#45167
[3] vultix#34
[4] vultix#48
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 29, 2022
I want to have this in place to implement [1] which satisfies a need we
ourselves have[2]. This is needed because the cause property is only
availble in the es2022 TS profile[3].

[1] vultix#34
[2] vultix#48
[3] microsoft/TypeScript#47020
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 29, 2022
This is useful to get access to the "underlying" error in global
exception-handling code for example.

Feature requested in [1] and I had a question about something similar as
well[2].

[1] vultix#34
[2] vultix#48

This change depends on #17 and #19 to be merged first (then the branch will be updated to contain these changes and the build will succeed).
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

No branches or pull requests

2 participants