taco-web icon indicating copy to clipboard operation
taco-web copied to clipboard

Create custom error classes for signing failures

Open theref opened this issue 5 months ago • 1 comments

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

  1. Create a new file: packages/taco/src/errors/signing-errors.ts

  2. 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';
  }
}
  1. Update packages/taco/src/sign.ts to use these custom errors

  2. 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

theref avatar Aug 20 '25 11:08 theref