Repository navigation
fix(register)!: validate JSON response - #109
Merged
Merged
Conversation
robertodauria
requested changes
Oct 8, 2026
bassosimone
force-pushed
the
fix/dontpanic
branch
from
October 8, 2026 13:49
7e1dc9a to
328dfe5
Compare
This patch updates `cmd/register/main.go` to handle `json.Unmarshal` errors, which are possible depending on what the response looks like. For example, a truncated response could cause `Unmarshal` to fail. We use `rtx.Must`, which logs and exits `1`. While there, prefer an error message and `Exit(1)` to panicking when the `register` API call failed. While there, notice that the response has many pointers, and act accordingly. Make sure it's well formed to avoid null dereferences a few lines below. Based on review comments, we normalized the file itself to use `log.Fatal/log.Fatalf` on error, so that the error message always consistently goes to the stderr. Also, based on review comments, we move all the checks at top, to ensure that the request is well formed with non-empty fields, to avoid writing just some of the files and then exiting because the data we received from the remote service is wrong. While there, note that logging the response is not a good idea once we get `200 OK`, because doing this might put the service account key on the systemd journal, which allows anyone in `adm` to read it. BREAKING CHANGE: `panic` exits with exit code `2` but I'm not convinced about keeping `2` in the new code: `2` is usually reserved for "usage error", and in the current codebase makes sense for "validating" input quickly, while `1` seems a better semantic translation of "the response does not look good, sorry, goodbye!".
bassosimone
force-pushed
the
fix/dontpanic
branch
from
October 8, 2026 14:34
328dfe5 to
03f38a8
Compare
bassosimone
marked this pull request as ready for review
October 8, 2026 14:35
Member
Author
|
@robertodauria I think I have addressed your feedback, can you take another look? 🙏 |
robertodauria
self-requested a review
October 8, 2026 14:59
robertodauria
approved these changes
Oct 8, 2026
Contributor
|
LGTM. Thanks! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This patch updates
cmd/register/main.goto handlejson.Unmarshalerrors, which are possible depending on what the response looks like. For example, a truncated response could causeUnmarshalto fail.While there, prefer an error message and
Exit(1)to panicking when theregisterAPI call failed.While there, notice that the response has many pointers, and act accordingly. Make sure it's well formed to avoid null dereferences a few lines below.
BREAKING CHANGE:
panicexits with exit code2but I'm not convinced about keeping2in the new code:2is usually reserved for "usage error", and in the current codebase makes sense for "validating" input quickly, while1seems a better semantic translation of "the response does not look good, sorry, goodbye!".This change is