Comprehensive error handling system for Ledger hardware wallet applications and libraries
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Error classes for user interaction scenarios including user refusals, permission issues, and input validation failures.
Errors for when users explicitly refuse or cancel operations on the device.
const UserRefusedOnDevice: CustomErrorFunc;
const UserRefusedAddress: CustomErrorFunc;
const UserRefusedFirmwareUpdate: CustomErrorFunc;
const UserRefusedAllowManager: CustomErrorFunc;
const UserRefusedDeviceNameChange: CustomErrorFunc;Usage Examples:
import {
UserRefusedOnDevice,
UserRefusedAddress,
UserRefusedFirmwareUpdate,
UserRefusedAllowManager
} from "@ledgerhq/errors";
// Handle transaction refusal
try {
await signTransaction();
} catch (error) {
if (error instanceof UserRefusedOnDevice) {
console.log("User cancelled transaction on device");
showMessage("Transaction was cancelled by user");
}
}
// Handle address verification refusal
try {
await verifyAddress();
} catch (error) {
if (error instanceof UserRefusedAddress) {
console.log("User refused to verify address");
}
}
// Handle firmware update refusal
if (userResponse === "denied") {
throw new UserRefusedFirmwareUpdate("User declined firmware update");
}
// Handle manager access refusal
if (!allowManagerAccess) {
throw new UserRefusedAllowManager("User denied manager access permissions");
}Errors related to system permissions and hardware access.
const NoAccessToCamera: CustomErrorFunc;
const CantScanQRCode: CustomErrorFunc;
const PairingFailed: CustomErrorFunc;Usage Examples:
import {
NoAccessToCamera,
CantScanQRCode,
PairingFailed
} from "@ledgerhq/errors";
// Handle camera permission
try {
await requestCameraAccess();
} catch (error) {
throw new NoAccessToCamera("Camera access required for QR code scanning");
}
// Handle QR code scanning issues
try {
const qrData = await scanQRCode();
} catch (error) {
if (error instanceof CantScanQRCode) {
console.log("Unable to scan QR code - check lighting and positioning");
}
}
// Handle device pairing failure
try {
await pairDevice();
} catch (error) {
if (error instanceof PairingFailed) {
console.log("Device pairing failed - please try again");
console.log("Ensure device is in pairing mode and nearby");
}
}Errors related to password validation and authentication.
const PasswordsDontMatchError: CustomErrorFunc;
const PasswordIncorrectError: CustomErrorFunc;Usage Examples:
import {
PasswordsDontMatchError,
PasswordIncorrectError
} from "@ledgerhq/errors";
// Handle password confirmation
function validatePasswordConfirmation(password: string, confirmPassword: string) {
if (password !== confirmPassword) {
throw new PasswordsDontMatchError("Password confirmation does not match");
}
}
// Handle incorrect password
try {
await authenticateUser(password);
} catch (error) {
if (error instanceof PasswordIncorrectError) {
console.log("Incorrect password entered");
attemptCount++;
if (attemptCount >= 3) {
lockAccount();
}
}
}
// Example usage in form validation
function handlePasswordForm(data: { password: string; confirmPassword: string }) {
try {
validatePasswordConfirmation(data.password, data.confirmPassword);
console.log("Password validation successful");
} catch (error) {
if (error instanceof PasswordsDontMatchError) {
showError("Passwords must match");
}
}
}