Skip to content

Implement a stable GuildPass SDK error hierarchy with safe serialisation #449

Description

@Lakes41

Difficulty: Expert
Type: Feature
Recommended labels (if available in this repo): error-handling, backend, type-safety, expert

Background

A public SDK must give consuming applications reliable ways to distinguish configuration failures, validation failures, transport failures, API failures, and cancellation without depending on fragile error-message matching.

This issue introduces the SDK-wide error contract independently of any specific GuildPass feature.

Problem

The rebuilt SDK does not yet expose a stable error hierarchy or machine-readable error codes.

Future contributors could otherwise create unrelated custom error types, causing an inconsistent public API.

Expected Outcome

Create a small, documented SDK error hierarchy with stable error codes, safe causal chaining, and controlled JSON serialisation.

Suggested Implementation

Introduce a base error such as:

class GuildPassError extends Error {
  readonly code: GuildPassErrorCode;
  readonly cause?: unknown;
}

Potential categories may include:

CONFIGURATION_ERROR
VALIDATION_ERROR
TRANSPORT_ERROR
HTTP_ERROR
TIMEOUT
ABORTED
RESPONSE_ERROR

The exact public model should be intentionally small and justified.

The implementation should:

  • use machine-readable error codes;
  • preserve instanceof Error behaviour;
  • set correct error names;
  • support error causes without blindly exposing them in serialised output;
  • allow safe metadata such as HTTP status where appropriate;
  • prevent secrets, raw request headers, tokens, or arbitrary nested objects from leaking via toJSON;
  • provide a reliable public type guard such as isGuildPassError;
  • remain compatible with JavaScript consumers as well as TypeScript consumers;
  • avoid dependency on specific transport or API modules.

Acceptance Criteria

  • A public base GuildPass SDK error type exists.
  • Stable machine-readable error codes are defined.
  • Error subclasses or discriminated categories are intentionally limited and documented.
  • instanceof Error and instanceof GuildPassError work correctly.
  • Error cause information can be retained internally.
  • Safe JSON serialisation omits unsafe cause content and secrets.
  • A type guard can identify SDK errors reliably.
  • Stack traces remain available in normal development use.
  • Unit tests cover construction, inheritance, type guards, serialisation, and cause handling.
  • Tests verify that unsafe arbitrary cause properties are not copied into serialised output.
  • pnpm typecheck passes.
  • pnpm build passes.
  • pnpm test passes.
  • No network request or domain endpoint implementation is included.

Likely Affected Files/Directories

src/errors/
src/index.ts
tests/

Independence Requirement

This issue must define the error model without requiring the transport or configuration issues to be merged first.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesThird CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsbackendBackend services, application logic, persistence integration, and server-side functionalityerror-handlingError handling improvements and error case management across the codebaseexpertExpert difficulty tasks requiring deep expertise and architectural decision-makingtype-safetyTypeScript type system improvements and strict type enforcement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions