You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(daemon): return errors from platform handlers - #1540
Platform HTTP handlers in pkg/daemon/platform/local_server.go now return error. A small adapter in handler.go (handlerFunc.ServeHTTP) turns the returned error into the response.
badRequest, forbidden, missingQueryParam wrap errors in a statusError with a status code.
Unwrapped errors default to 500. Wrapped status errors keep their code via errors.AsType.
writeJSON replaces tryJSON with the same json.Marshal output, no trailing newline, and the same Content-Type.
Routes use mux.Handle(..., handlerFunc(...)). watchWorkspaces and throttle are streaming and unchanged.
Why
Each handler repeated http.Error plus return. Returning errors lets one place set status and text. Status codes, message text, and response bodies are unchanged.
Validation
mise run cli:format
mise run cli:lint:ci
golangci-lint run --new-from-rev=origin/main ./pkg/...: 0 issues
go build ./...
go test ./pkg/daemon/...
GOOS=windows go build ./pkg/daemon/...
GOOS=linux go build ./pkg/daemon/...
New tests in handler_test.go cover the adapter status mapping (plain, bad request, forbidden, wrapped, nil) and the missing-query-parameter 400 responses.
CodeRabbit CLI
coderabbit review --agent --committed --base-commit adbf08d32: completed, 0 findings on the 3 changed files.
Auto-merge
Eligible under the auto-refactor policy: 3 files (2 non-test), 406 changed lines (255 added, 151 removed), behaviour-preserving, no existing tests changed.
Summary by CodeRabbit
Bug Fixes
HTTP endpoints now return consistent error responses: invalid requests receive a 400 status, access-denied responses retain a 403 status, and unexpected errors receive a 500 status.
Error messages are included in responses, including when errors are wrapped.
Successful JSON responses remain available, and requests for unavailable workspaces or registries retain their existing response behavior.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 1bea127f-12c1-4ed5-b3c1-b6ebcc19a0bd
📥 Commits
Reviewing files that changed from the base of the PR and between adbf08d and 6a49736.
📒 Files selected for processing: 3
pkg/daemon/platform/handler.go
pkg/daemon/platform/handler_test.go
pkg/daemon/platform/local_server.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Platform HTTP handlers now return errors to a shared wrapper, which selects the HTTP status and writes the error response. Successful JSON responses use a shared helper. Tests cover error responses and missing required query parameters.
sequenceDiagram
participant HTTPClient
participant handlerFunc
participant localServerStatus as localServer.status
participant writeJSON
participant ResponseWriter
HTTPClient->>handlerFunc: send request
handlerFunc->>localServerStatus: invoke wrapped handler
alt handler succeeds
localServerStatus->>writeJSON: marshal status response
writeJSON->>ResponseWriter: set JSON header and write body
else handler returns error
handlerFunc->>ResponseWriter: write status and error text
end
Loading
Suggested reviewers:pascalbreuninger
Merge Risk:⚪ Minimal · up to 6a497
The reviewed response changes have no established issue blocking merge; proceed with normal checks.
Security architecture risk:⚪ Minimal · up to 6a497
The shared response handling preserves existing routes, credential access paths, backend operations and response formats. No material security risk introduced or worsened by this refactor was identified.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The changed contract affects ordinary local-server responses, including credential and mutation endpoints. Because route reachability, forwarding and backend inputs are preserved, the inspected change does not expand the independently reachable credential or workspace scope.
Trust Boundaries and Controls
observed — The adapter neither replaces caller identity nor introduces an authorization decision. Existing local-server transport assumptions and downstream client authority remain in place, as do the outer panic-recovery and logging wrappers. This does not establish which external processes can access the deployed daemon socket.
Resilience and Maintainability Implications
observed — Shutdown cleanup remains owned by localServer.Close. Its buffered stop-channel send and listener-close handling are unchanged, so repetition and concurrency limitations are not introduced by centralized error rendering.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: platform handlers now return errors.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
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
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
Platform HTTP handlers in
pkg/daemon/platform/local_server.gonow returnerror. A small adapter inhandler.go(handlerFunc.ServeHTTP) turns the returned error into the response.badRequest,forbidden,missingQueryParamwrap errors in astatusErrorwith a status code.errors.AsType.writeJSONreplacestryJSONwith the samejson.Marshaloutput, no trailing newline, and the sameContent-Type.mux.Handle(..., handlerFunc(...)).watchWorkspacesandthrottleare streaming and unchanged.Why
Each handler repeated
http.Errorplusreturn. Returning errors lets one place set status and text. Status codes, message text, and response bodies are unchanged.Validation
mise run cli:formatmise run cli:lint:cigolangci-lint run --new-from-rev=origin/main ./pkg/...: 0 issuesgo build ./...go test ./pkg/daemon/...GOOS=windows go build ./pkg/daemon/...GOOS=linux go build ./pkg/daemon/...New tests in
handler_test.gocover the adapter status mapping (plain, bad request, forbidden, wrapped, nil) and the missing-query-parameter 400 responses.CodeRabbit CLI
coderabbit review --agent --committed --base-commit adbf08d32: completed, 0 findings on the 3 changed files.Auto-merge
Eligible under the auto-refactor policy: 3 files (2 non-test), 406 changed lines (255 added, 151 removed), behaviour-preserving, no existing tests changed.
Summary by CodeRabbit