MCPcopy
hub / github.com/larksuite/cli / matchesTypedError

Function matchesTypedError

internal/errclass/classify_test.go:66–99  ·  view source on GitHub ↗

matchesTypedError reports whether err is the typed-error variant identified by wantTyped (e.g. "ValidationError" → *errs.ValidationError). Used by the ExitCode matrix so a wrong-Category routing (e.g. CategoryValidation falling through to *APIError) fails loudly instead of passing on Category alone.

(err error, wantTyped string)

Source from the content-addressed store, hash-verified

64// ExitCode matrix so a wrong-Category routing (e.g. CategoryValidation falling
65// through to *APIError) fails loudly instead of passing on Category alone.
66func matchesTypedError(err error, wantTyped string) bool {
67 switch wantTyped {
68 case "PermissionError":
69 var x *errs.PermissionError
70 return errors.As(err, &x)
71 case "AuthenticationError":
72 var x *errs.AuthenticationError
73 return errors.As(err, &x)
74 case "ValidationError":
75 var x *errs.ValidationError
76 return errors.As(err, &x)
77 case "NetworkError":
78 var x *errs.NetworkError
79 return errors.As(err, &x)
80 case "ConfigError":
81 var x *errs.ConfigError
82 return errors.As(err, &x)
83 case "InternalError":
84 var x *errs.InternalError
85 return errors.As(err, &x)
86 case "ConfirmationRequiredError":
87 var x *errs.ConfirmationRequiredError
88 return errors.As(err, &x)
89 case "SecurityPolicyError":
90 var x *errs.SecurityPolicyError
91 return errors.As(err, &x)
92 case "APIError":
93 // APIError is the default fallback; use a direct type assertion to avoid
94 // matching against typed subclasses that also satisfy IsAPI.
95 _, ok := err.(*errs.APIError)
96 return ok
97 }
98 return false
99}
100
101func TestBuildAPIError_ExitCodeMatrix(t *testing.T) {
102 cases := []struct {

Callers 1

Calls 1

AsMethod · 0.80

Tested by

no test coverage detected