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.ts to 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
Overview
The signing module currently throws generic
Errorobjects with string messages. We should create custom error classes to improve error handling, debugging, and allow consumers to catch specific error types.Current Behavior
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.tsImplement the following error classes:
Update
packages/taco/src/sign.tsto use these custom errorsExport the error classes from the package's main index
Files to Change
packages/taco/src/errors/signing-errors.tspackages/taco/src/sign.tspackages/taco/src/index.ts(to export error classes)packages/taco/test/taco-sign.test.ts(to test for specific error types)Definition of Done