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 database operations and configuration issues in Ledger applications.
interface DatabaseConfig {
dbPath: string;
password?: string;
connectionTimeout?: number;
maxRetries?: number;
}Errors related to database path configuration and setup.
const NoDBPathGiven: CustomErrorFunc;Usage Examples:
import { NoDBPathGiven } from "@ledgerhq/errors";
// Validate database path configuration
function initializeDatabase(config: DatabaseConfig) {
if (!config.dbPath || config.dbPath.trim() === "") {
throw new NoDBPathGiven("Database path must be specified in configuration");
}
return openDatabase(config.dbPath);
}
// Example database initialization
try {
const db = initializeDatabase({ dbPath: process.env.DB_PATH });
} catch (error) {
if (error instanceof NoDBPathGiven) {
console.log("Please set DB_PATH environment variable");
}
}Errors related to database password validation and authentication.
const DBWrongPassword: CustomErrorFunc;Usage Examples:
import { DBWrongPassword } from "@ledgerhq/errors";
// Handle database password validation
async function authenticateDatabase(password: string) {
try {
await verifyDatabasePassword(password);
} catch (error) {
throw new DBWrongPassword("Incorrect database password provided");
}
}
// Example database access with password
try {
await authenticateDatabase(userPassword);
const db = await openSecureDatabase();
} catch (error) {
if (error instanceof DBWrongPassword) {
console.log("Invalid password - please try again");
promptForPassword();
}
}Errors related to database state management and reset operations.
const DBNotReset: CustomErrorFunc;Usage Examples:
import { DBNotReset } from "@ledgerhq/errors";
// Handle database reset validation
async function initializeCleanDatabase() {
const isReset = await checkDatabaseResetStatus();
if (!isReset) {
throw new DBNotReset("Database must be reset before initialization");
}
return createNewDatabase();
}
// Example database reset workflow
try {
await resetDatabase();
const db = await initializeCleanDatabase();
} catch (error) {
if (error instanceof DBNotReset) {
console.log("Database reset failed - please try manual reset");
}
}
// Database migration with reset requirement
async function migrateDatabase(fromVersion: string, toVersion: string) {
if (requiresReset(fromVersion, toVersion)) {
try {
await resetDatabase();
await initializeCleanDatabase();
} catch (error) {
if (error instanceof DBNotReset) {
throw new Error(`Migration from ${fromVersion} to ${toVersion} requires database reset`);
}
}
}
}