Skip to content

[Feature]: Add .addNote() method to ErrorInstance #8

Closed

Description

@martyy-code

Feature Description

Implement the .addNote() method on the ErrorInstance type. This method enriches errors with additional context notes, inspired by Python 3.11's add_note() functionality.

Problem It Solves

  • Errors often need additional context discovered at runtime
  • Notes provide better debugging information without changing the core API
  • Enables rich error enrichment after catching

Proposed Solution

import { error, raise } from '@deessejs/errors';

const AppError = error({ name: 'AppError' });

try {
  processData(input);
} catch (err) {
  raise(
    AppError().addNote('Processing failed at line 42')
  );
}

// Multiple notes supported
raise(
  AppError()
    .addNote('Attempt 1 failed')
    .addNote('Retrying...')
    .addNote('Attempt 2 failed')
);

Implementation approach:

  • Add addNote(note: string): ErrorInstance<T> method to ErrorInstance type
  • Support chaining multiple notes
  • Notes must be preserved through .from() chaining

Alternatives Considered

  • Type guards approach (deferred to v1.2.0)
  • Context injection via withContext() (deferred to v2.0.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions