-
Notifications
You must be signed in to change notification settings - Fork 928
chore: create interface for pkgs to return codersdk errors #18719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
b43bd8e
to
15a6ca1
Compare
f0dd768
to
a87678d
Compare
96c83c7
to
8d594a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have nits about naming and usage conventions, but these aren't blocking.
Diagnostics hcl.Diagnostics | ||
KeyedDiagnostics map[string]hcl.Diagnostics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: What's the difference between Diagnostics
and KeyedDiagnostics
?
When should you use one or the other?
func (e *DiagnosticError) Append(key string, diag *hcl.Diagnostic) { | ||
e.Extend(key, hcl.Diagnostics{diag}) | ||
} | ||
|
||
func (e *DiagnosticError) Extend(key string, diag hcl.Diagnostics) { | ||
if e.KeyedDiagnostics == nil { | ||
e.KeyedDiagnostics = make(map[string]hcl.Diagnostics) | ||
} | ||
if _, ok := e.KeyedDiagnostics[key]; !ok { | ||
e.KeyedDiagnostics[key] = hcl.Diagnostics{} | ||
} | ||
e.KeyedDiagnostics[key] = e.KeyedDiagnostics[key].Extend(diag) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/quibble: Similarly here, when should you use Append()
vs Extend()
?
I would expect to use Append()
like this:
var derr DiagnosticError
thing, diags := preview.Frobulate()
if diags.HasErrors() {
derr.Append(diags...)
}
type CoderSDKError interface { | ||
Response() (int, codersdk.Response) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should probably be named Responder
or Responser
?
The dynamic parameter code lives in a package far removed from the httpapi and handlers. This interface allows it to create rich codersdk errors and pass them up to the
wsbuilder
error handling.This interface should probably be used in more places. I got tired of making custom error handling code for unique types.