8000 chore: create interface for pkgs to return codersdk errors by Emyrk · Pull Request #18719 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: PR fixups, renames and comments
  • Loading branch information
Emyrk committed Jul 3, 2025
commit 46146b99f904bd3afe790e8026697b55b7134259
9 changes: 7 additions & 2 deletions coderd/dynamicparameters/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ func TagValidationError(diags hcl.Diagnostics) *DiagnosticError {
}

type DiagnosticError struct {
Message string
Diagnostics hcl.Diagnostics
// Message is the human-readable message that will be returned to the user.
Message string
// Diagnostics are top level diagnostics that will be returned as "Detail" in the response.
Diagnostics hcl.Diagnostics
// KeyedDiagnostics translate to Validation errors in the response. A key could
// be a parameter name, or a tag name. This allows diagnostics to be more closely
// associated with a specific index/parameter/tag.
KeyedDiagnostics map[string]hcl.Diagnostics
}

Expand Down
6 changes: 3 additions & 3 deletions coderd/httpapi/httperror/responserror.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"github.com/coder/coder/v2/codersdk"
)

type CoderSDKError interface {
type Responder interface {
Response() (int, codersdk.Response)
}

func IsCoderSDKError(err error) (CoderSDKError, bool) {
var responseErr CoderSDKError
func IsResponder(err error) (Responder, bool) {
var responseErr Responder
if errors.As(err, &responseErr) {
return responseErr, true
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/httpapi/httperror/wsbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func WriteWorkspaceBuildError(ctx context.Context, rw http.ResponseWriter, err error) {
if responseErr, ok := IsCoderSDKError(err); ok {
if responseErr, ok := IsResponder(err); ok {
code, resp := responseErr.Response()

httpapi.Write(ctx, rw, code, resp)
Expand Down
2 changes: 1 addition & 1 deletion coderd/wsbuilder/wsbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ func TestWsbuildError(t *testing.T) {
Message: msg,
}

respErr, ok := httperror.IsCoderSDKError(buildErr)
respErr, ok := httperror.IsResponder(buildErr)
require.True(t, ok, "should be a Coder SDK error")

code, resp := respErr.Response()
Expand Down
Loading
0