Skip to content

Replace string-matched error classification with typed errors#28

Merged
andreagrandi merged 1 commit into
masterfrom
typed-error-classification
May 21, 2026
Merged

Replace string-matched error classification with typed errors#28
andreagrandi merged 1 commit into
masterfrom
typed-error-classification

Conversation

@andreagrandi

Copy link
Copy Markdown
Owner

Summary

JSON error classification previously relied on matching substrings in error messages, making --error-format json output brittle when wording changed (e.g. a 401 body of Unauthenticated vs Unauthorized).

This introduces a new internal/mberr package with typed errors and rewrites classification to inspect error types via errors.As instead of message text.

Changes

  • New internal/mberr package with typed errors:
    • ConfigError — missing/invalid environment configuration
    • APIError — non-2xx responses, with IsAuth() for 401/403
    • TimeoutError / CanceledError — context deadline/cancellation
    • RequestError — wraps a failure for a specific ResourceKind (database, table, field, dashboard, card, dashboard parameter)
    • ResolutionError — name→ID resolution failures
    • ParameterizedQueryError — rejected parameterized queries
  • classifyError now matches error types via errors.As; resource-specific suggestions derive from ResourceKind rather than substring matches.
  • Error producers updated to return typed errors: config.go, client.go, cards.go, dashboards.go, query.go, card.go.

Testing

  • make build, make vet, gofmt — clean
  • tests/error_format_test.go rewritten to construct typed errors directly; 19 subtests cover config, auth, API (incl. resource-specific 404s), resolution, timeout/cancellation, and errors.As unwrapping of wrapped errors
  • Smoke-tested all four acceptance-criteria categories against a live API: CONFIG_ERROR, AUTH_ERROR, API_ERROR (404 with resource-specific suggestion), RESOLUTION_ERROR

Acceptance criteria

  • Structured JSON errors do not depend on fragile substring matching
  • Tests cover config, auth, API, and resolution error classification
  • Existing --error-format json behavior remains compatible

Closes #12

Add an internal/mberr package with typed errors for config, API, auth,
timeout, cancellation, resource requests, name resolution, and
parameterized queries. classifyError now inspects error types via
errors.As rather than matching message substrings, so structured
--error-format json output stays reliable when wording changes.

Closes #12
@andreagrandi andreagrandi merged commit 158cded into master May 21, 2026
7 checks passed
@andreagrandi andreagrandi deleted the typed-error-classification branch May 21, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace string-matched error classification with typed errors

1 participant