fix: propagate native error message instead of discarding it#109
Open
guidofawkes328 wants to merge 1 commit into
Open
fix: propagate native error message instead of discarding it#109guidofawkes328 wants to merge 1 commit into
guidofawkes328 wants to merge 1 commit into
Conversation
Android rejected create()/get() with the mapped error code as both the code and the message (`promise.reject(errorCode, errorCode)`), discarding the underlying `CreateCredentialException.errorMessage` (e.g. "RP ID cannot be validated."). JS callers therefore only saw a generic, often misleading message and could not diagnose configuration problems. - Android: reject with the native `errorMessage` as the message while keeping the existing code, and add a `catch (Throwable)` fallback so a non-CredentialException failure rejects with detail instead of leaving the promise unsettled (a hang). - iOS: align the get() decode-catch with create() so it rejects with a mapped code + `localizedDescription` instead of the verbose debugDescription for both fields. - JS: prefer the native message over the generic per-code fallback when it carries additional detail, keeping the mapped error code unchanged. Error codes are unchanged, so programmatic `.error` checks keep working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Android,
create()/get()reject with the coarse mapped error code as both the code and the message:This discards the real
CreateCredentialException.errorMessage(e.g."RP ID cannot be validated."). The JS wrapper (handleNativeError) then maps the code to a hardcoded generic string, so callers only ever see something like "The request failed. No Credentials were returned." — misleading, and useless for diagnosing configuration problems (RP ID / assetlinks mismatches, etc.).Several distinct DOM errors (
NotAllowedError,DataError= "RP ID cannot be validated",SecurityError) all collapse toRequestFailed, so the code alone cannot tell them apart — the message is the only signal, and it was being thrown away.There was also no fallback
catcharound the coroutine body, so a non-CredentialExceptionfailure could leave the promise unsettled (a hang).Fix
Non-breaking — error codes are unchanged, so programmatic
.error === 'RequestFailed'checks keep working. Only the message now carries the native detail.PasskeyModule.kt): reject with the native message while keeping the code:create()andget(), plus acatch (e: Throwable)fallback so unexpected failures reject with detail instead of hanging.Passkey.swift): the primary error path already propagatederror.localizedDescription. Aligned theget()decode-catchwithcreate()so it rejects with a mapped code +localizedDescriptioninstead of the verbosedebugDescriptionfor both fields.PasskeyError.ts): prefer the native message over the generic per-code fallback when it carries additional detail; fall back to the existing generic message otherwise. Addedmessage?: stringtoTNativeError.Before / After
Given a native failure with
errorMessage = "RP ID cannot be validated.":{ error: 'RequestFailed', message: 'The request failed. No Credentials were returned.' }{ error: 'RequestFailed', message: 'RP ID cannot be validated.' }Verification
yarn tsc --noEmit,eslint, and the Jest suite all pass. Kotlin/Swift were not compiled in isolation but the edits are syntactically consistent with the surrounding code and existing imports.Related
Android#68 ("[50152] RP ID cannot be validated on Android") — the underlying message is now surfaced to callers.