Replace string-matched error classification with typed errors#28
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JSON error classification previously relied on matching substrings in error messages, making
--error-format jsonoutput brittle when wording changed (e.g. a 401 body ofUnauthenticatedvsUnauthorized).This introduces a new
internal/mberrpackage with typed errors and rewrites classification to inspect error types viaerrors.Asinstead of message text.Changes
internal/mberrpackage with typed errors:ConfigError— missing/invalid environment configurationAPIError— non-2xx responses, withIsAuth()for 401/403TimeoutError/CanceledError— context deadline/cancellationRequestError— wraps a failure for a specificResourceKind(database, table, field, dashboard, card, dashboard parameter)ResolutionError— name→ID resolution failuresParameterizedQueryError— rejected parameterized queriesclassifyErrornow matches error types viaerrors.As; resource-specific suggestions derive fromResourceKindrather than substring matches.config.go,client.go,cards.go,dashboards.go,query.go,card.go.Testing
make build,make vet,gofmt— cleantests/error_format_test.gorewritten to construct typed errors directly; 19 subtests cover config, auth, API (incl. resource-specific 404s), resolution, timeout/cancellation, anderrors.Asunwrapping of wrapped errorsCONFIG_ERROR,AUTH_ERROR,API_ERROR(404 with resource-specific suggestion),RESOLUTION_ERRORAcceptance criteria
--error-format jsonbehavior remains compatibleCloses #12