Skip to content

Commit

Permalink
Catch error on key type update
Browse files Browse the repository at this point in the history
This is a workaround for unexpected authenticator attachments.
  • Loading branch information
nmattia committed Dec 5, 2022
1 parent 58a6336 commit b7ffbd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/frontend/src/utils/iiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ export class Connection {

const attachmentInfo = identity.getAuthenticatorAttachment();
if (attachmentInfo !== undefined) {
this.updateKeyTypeIfNecessary(devices, attachmentInfo, connection);
try {
this.updateKeyTypeIfNecessary(devices, attachmentInfo, connection);
} catch (e) {
console.warn("Could not update key type:", e);
}
}

return {
Expand Down Expand Up @@ -283,7 +287,10 @@ export class Connection {
device.key_type = { platform: null };
break;
default:
unreachable(attachmentInfo.authenticatorAttachment);
unreachable(
attachmentInfo.authenticatorAttachment,
`unexpected authenticator attachment: ${attachmentInfo.authenticatorAttachment}`
);
break;
}
// we purposely do not await the promise as we just optimistically update
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export function iOSOrSafari(): boolean {
}

/* A function that can never be called. Can be used to prove that all type alternatives have been exhausted. */
export function unreachable(_: never): never {
throw new Error("The impossible happened");
export function unreachable(_: never, reason?: string): never {
throw new Error(`Unexpected error ${reason ?? ""}`);
}

/* Wrap an unknown value as an error and try to extract a string from it */
Expand Down

0 comments on commit b7ffbd1

Please sign in to comment.