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

Fix issue where error reporting wrong instanceof #543

Merged
merged 1 commit into from
Nov 19, 2021

Conversation

adamjmcgrath
Copy link
Contributor

Description

Using the instanceof operator against the AccessTokenError constructor always returns false, even if the object that is being tested is actually an instance of AccessTokenError.

This is an issue introduced in nextjs-auth0 v1.5.0 by microsoft/TypeScript#13965 when we downgraded the compilation target to es5 to support IE11 in c248efe#diff-3ae20d611c1c7263a9c1bce0449291ebfea1c5d578b3fcdbb596353ad885db25R19

Using the workaround here https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work

References

fixes #535

Testing

Set the target for jest to be the same as the main binary, so I could add a test case for this regression.
Using target es5 on jest meant I had to add a couple of ignore next's to resolve an issue in istanbul (see gotwarlost/istanbul#690)

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

@adamjmcgrath adamjmcgrath added the review:small Small review label Nov 18, 2021
@adamjmcgrath adamjmcgrath requested a review from a team as a code owner November 18, 2021 16:23
@vercel
Copy link

vercel bot commented Nov 18, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/auth0/nextjs-auth0/7SxTE59cysaY4YZWGZF3pbbeAPRb
✅ Preview: Canceled

@@ -149,13 +149,6 @@
}
},
"preset": "ts-jest",
"globals": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using same target as project (es5) so I can have a regression test for this issue

@@ -8,6 +8,7 @@ import { HttpError } from 'http-errors';
export class AccessTokenError extends Error {
public code: string;

/* istanbul ignore next */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import { AccessTokenError, HandlerError } from '../../src/utils/errors';

describe('errors', () => {
test('should be instance of themselves', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Believe it or not, this test will fail in TS with target: es5 without the Object.setPrototypeOf(this, ThisError.prototype); workaround

@adamjmcgrath adamjmcgrath merged commit f7323d0 into main Nov 19, 2021
@adamjmcgrath adamjmcgrath mentioned this pull request Dec 16, 2021
@evansims evansims deleted the error-instanceof branch July 5, 2022 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:small Small review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can no longer check if an error is instance of AccessTokenError
2 participants