Skip to content

Add typed error subclasses for each error code #422

Description

@Lakes41

Difficulty: Intermediate
Type: Refactor
Recommended labels (if available in this repo): enhancement, dx, sdk

Background

src/errors/errorCodes.ts defines error codes and src/errors/GuildPassError.ts provides a base error class, but consumers currently have to check error.code manually to distinguish error types rather than using instanceof checks against specific error classes.

Problem

Without typed subclasses, catching specific error conditions (e.g. NetworkError vs InvalidConfigError vs AccessDeniedError) requires string/enum comparisons scattered through consumer code, which is error-prone and not very ergonomic TypeScript.

Expected Outcome

Each entry in errorCodes.ts has a corresponding typed subclass of GuildPassError (e.g. class NetworkError extends GuildPassError), all exported from src/errors/index.ts (or equivalent), so consumers can do catch (e) { if (e instanceof NetworkError) ... }.

Suggested Implementation

Generate or hand-write one subclass per error code, ensuring each still carries the same code field for backward compatibility with existing string-based checks. Update internal throw sites in src/errors/errorTypes.ts and call sites across src/ to throw the new subclasses instead of the generic base class where applicable.

Acceptance Criteria

  • Every error code in errorCodes.ts has a matching typed subclass
  • All subclasses remain instanceof GuildPassError and retain the code property for backward compatibility
  • Existing throw sites updated to use the specific subclasses
  • Unit tests verify instanceof checks work correctly for each subclass
  • pnpm test:run and pnpm typecheck pass

Likely Affected Files/Directories

  • src/errors/GuildPassError.ts
  • src/errors/errorCodes.ts
  • src/errors/errorTypes.ts
  • src/errors/error.types.ts

Metadata

Metadata

Labels

GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewards

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions