You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello @Mykhailo-Sichkaruk, thanks for the suggestion! This is a great idea, I see how it'd be nice to bring some order to the many more errors that @simplewebauthn/server might raise. I'll begin thinking about this and try to implement a custom error like @simplewebauthn/browser's WebAuthnError from #367 like you called out... 🤔
This can help not only in handling errors, but also in understanding for users of the lib how errors relate to each other and how they should be handled.
Thanks for keeping this issue alive @junderw. I still think this is worth doing. I'm trying to get v14.0.0 out the door, but it's got enough features in it that I'm going to wait till after that goes out to begin working on this as a "v14.1.0" release.
I noticed pull requests are locked. Would you be interested in taking a patch if I have some time to work on it?
I appreciate the offer but will respectfully decline. I'm all ears for any proposals you might have for how to pull this off though. My game plan remains to add something like @simplewebauthn/browser's WebAuthnError into @simplewebauthn/server, with a code property that gets set to some enum string like ERROR_CEREMONY_ABORTED, etc... Then I'd update everything to consistently throw WebAuthnError.
I always think of this issue when I throw new Error(...) in @simplwebauthn/server. So while working on #800 I thought it might be possible to establish a pattern that'll finally address this issue (not with #800, but definitely in the short term):
exportclassSimpleWebAuthnErrorextendsError{code: SimpleWebAuthnErrorCode;constructor({ message, code, cause }: {message: string;code: SimpleWebAuthnErrorCode;cause?: Error;}){super(message,{ cause });this.name='SimpleWebAuthnError';this.code=code;}}exportclassPQCNotSupportedErrorextendsSimpleWebAuthnError{constructor(alg: COSEALG){constwebCryptoAlg=mapCoseAlgToWebCryptoKeyAlgName(alg);constmessage=`This runtime's WebCrypto.subtle does not support use of ${webCryptoAlg}`;super({ message,code: 'RUNTIME_NO_PQC_SUPPORT'});}}exporttypeSimpleWebAuthnErrorCode='RUNTIME_NO_PQC_SUPPORT';
Then even if I get fancy with subclasses of SimpleWebAuthnError users of the library could still use a simple error instanceof SimpleWebAuthnError to know it's something out of this library 🤔
And in @simplewebauthn/browser I could add a simple subclass of Error so that even the existing WebAuthnError in that library could be detected with error instanceof SimpleWebAuthnError without breaking existing code that handles WebAuthnError:
Activity
MasterKale commentedon Dec 6, 2024
Hello @Mykhailo-Sichkaruk, thanks for the suggestion! This is a great idea, I see how it'd be nice to bring some order to the many more errors that @simplewebauthn/server might raise. I'll begin thinking about this and try to implement a custom error like @simplewebauthn/browser's
WebAuthnErrorfrom #367 like you called out... 🤔Mykhailo-Sichkaruk commentedon Dec 9, 2024
Thanks for considering this feature 😊
I'm also thinking how we can improve error handling
I have a related idea: grouping errors to handle not just one error but set of related errors.
For example, a
PublicKeyErrorcategory could group all public key-related issues, such as:PublicKeyMissingAlgErrorPublicKeyInvalidAlgErrorThis could be implemented with inheritance:
Or, alternatively, using a list of error codes:
This can help not only in handling errors, but also in understanding for users of the lib how errors relate to each other and how they should be handled.
junderw commentedon Aug 25, 2026
Ran into this today, had to write some regex to match the message string passed into an error deep in this library.
Luckily it's open source, and I wrote some unit tests to check for regressions if I ever update and the message changes.
I noticed pull requests are locked. Would you be interested in taking a patch if I have some time to work on it?
MasterKale commentedon Aug 29, 2026
Thanks for keeping this issue alive @junderw. I still think this is worth doing. I'm trying to get v14.0.0 out the door, but it's got enough features in it that I'm going to wait till after that goes out to begin working on this as a "v14.1.0" release.
I appreciate the offer but will respectfully decline. I'm all ears for any proposals you might have for how to pull this off though. My game plan remains to add something like @simplewebauthn/browser's
WebAuthnErrorinto @simplewebauthn/server, with acodeproperty that gets set to some enum string likeERROR_CEREMONY_ABORTED, etc... Then I'd update everything to consistently throwWebAuthnError.junderw commentedon Sep 3, 2026
Browser's
WebAuthnErroris perfect. Can't wait to get rid of all those regression tests against error messages (AI helped a lot though).No rush. Just don't change the error messages until then! 😆
Perhaps this starts the progress on #646
MasterKale commentedon Sep 4, 2026
I always think of this issue when I
throw new Error(...)in @simplwebauthn/server. So while working on #800 I thought it might be possible to establish a pattern that'll finally address this issue (not with #800, but definitely in the short term):https://github.com/MasterKale/SimpleWebAuthn/blob/10b4f53802290c867edcdc67072be069fa2ed8a3/packages/server/src/errors/index.ts
Then even if I get fancy with subclasses of
SimpleWebAuthnErrorusers of the library could still use a simpleerror instanceof SimpleWebAuthnErrorto know it's something out of this library 🤔MasterKale commentedon Sep 4, 2026
And in @simplewebauthn/browser I could add a simple subclass of Error so that even the existing
WebAuthnErrorin that library could be detected witherror instanceof SimpleWebAuthnErrorwithout breaking existing code that handlesWebAuthnError: