backend: Stop parseKubeConfig after bad JSON#5599
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the backend /parseKubeConfig handler where it would continue executing after failing to decode an invalid JSON request body, potentially attempting to write a second response. It adds the missing early return and introduces a regression test to ensure the handler responds with only the expected 400 Bad Request.
Changes:
- Add an early
returnafterhttp.Error(...)on JSON decode failure inparseKubeConfig. - Add a regression test asserting malformed JSON yields a single
400response with the expected error body.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| backend/cmd/stateless.go | Stops handler execution immediately after invalid JSON is detected to avoid double-writing responses. |
| backend/cmd/stateless_test.go | Adds a regression test ensuring malformed JSON returns only the expected 400 error response. |
|
@skoeva |
illume
left a comment
There was a problem hiding this comment.
Thanks for this PR.
the PR has a merge-main commit; please rebase against main to keep the history clean.
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 6 changed files in this pull request and generated 4 comments.
Files not reviewed (2)
- plugins/headlamp-plugin/package-lock.json: Language not supported
- plugins/headlamp-plugin/template/package-lock.json: Language not supported
27e348a to
01b3111
Compare
@illume |
illume
left a comment
There was a problem hiding this comment.
Thanks for working on this.
would you mind rebasing this branch on top of the latest main rather than merging it in?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
illume
left a comment
There was a problem hiding this comment.
Thanks for these changes.
can you please rebase against main to remove the merge main commit?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
illume
left a comment
There was a problem hiding this comment.
Thanks for working on this.
would you mind rebasing this branch on top of the latest main rather than merging it in?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
it looks like there's a merge-main commit in this PR — could you rebase onto main instead?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
it looks like there's a merge-main commit in this PR — could you rebase onto main instead?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
The backend test job in CI is failing. Run cd backend && go test ./... to reproduce the errors locally.
How to run the backend tests
Run cd backend && go test ./... to see all failures. Fix the failing tests and commit the result.
illume
left a comment
There was a problem hiding this comment.
Thanks for these changes.
can you please rebase against main to remove the merge main commit?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
Can you please address the open review comments? Once you've resolved each one, please mark it as resolved.
3fbc9f1 to
3df5211
Compare
438b147 to
aae9951
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: harrshita123 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
aae9951 to
3ea1f81
Compare
@illume |
fb76cca to
6dc8d2c
Compare
Summary
This PR fixes a backend bug where
/parseKubeConfigcontinued processing after receiving an invalid JSON request body.The handler already returned a
400 Bad Request, but it did not stop execution afterward. As a result, it could continue with an empty request payload and try to write a second response. This change adds the missing early return and covers the behavior with a regression test.Related Issue
Fixes #5598
Changes
parseKubeConfig.400 Bad Requestresponse.Steps to Test
Run the focused backend test:
Run backend lint:
Run the full backend test suite:
Screenshots (if applicable)
Not applicable. This is a backend request-handling fix.
Notes for the Reviewer
The production change is intentionally small: one missing
returnafter the bad request response. Valid kubeconfig parsing behavior is unchanged.