taco-web
taco-web copied to clipboard
Create custom error classes for signing failures
Overview
The signing module currently throws generic Error objects with string messages. We should create custom error classes to improve error handling, debugging, and allow consumers to catch specific error types.
Current Behavior
throw new Error(ERR_INSUFFICIENT_SIGNATURES(porterSignResult.errors));
throw new Error(ERR_MISMATCHED_HASHES(hashToSignatures));
Expected Behavior
Create specific error classes that extend Error and provide structured error information.
Implementation Plan
-
Create a new file:
packages/taco/src/errors/signing-errors.ts -
Implement the following error classes:
export class SigningError extends Error {
constructor(message: string) {
super(message);
this.name = 'SigningError';
}
}
export class InsufficientSignaturesError extends SigningError {
constructor(
public readonly errors: unknown,
public readonly threshold: number,
public readonly received: number
) {
super(`Threshold of signatures not met: required ${threshold}, received ${received}`);
this.name = 'InsufficientSignaturesError';
}
}
export class MismatchedHashesError extends SigningError {
constructor(
public readonly hashToSignatures: Map<string, { [ursulaAddress: string]: TacoSignature }>
) {
super('Multiple mismatched hashes found during signing');
this.name = 'MismatchedHashesError';
}
}
-
Update
packages/taco/src/sign.tsto use these custom errors -
Export the error classes from the package's main index
Files to Change
- Create:
packages/taco/src/errors/signing-errors.ts - Update:
packages/taco/src/sign.ts - Update:
packages/taco/src/index.ts(to export error classes) - Update:
packages/taco/test/taco-sign.test.ts(to test for specific error types)
Definition of Done
- [ ] Custom error classes created
- [ ] All generic Error throws replaced with specific error types
- [ ] Error classes exported from package
- [ ] Tests updated to check for specific error types
- [ ] Error classes include relevant debugging information as properties