Repository navigation
Explain the errors the Cinc server returns - #318
Merged
Merged
Conversation
tas50
force-pushed
the
errors-server-responses
branch
from
November 27, 2026 06:39
50dbcea to
59987fd
Compare
Every server error used to reach the user as cinc-api's raw text, e.g. "cinc: GET /organizations/acme/nodes/web1: 404: Cannot load node web1". Execute now prints client.ExplainFor, which retells a 400, 401, 403, 404, 409, 413 or 5xx as what went wrong and what to do, naming the object (worked out from the request path), the organization, and the client, server, key and profile the command signed with. The server's own message and the request stay in the text. - 401 is split by the server's message: wrong key, unknown client or user, clock skew, or all three when the message says nothing. - 403 names the action and object and the acl commands to fix it, or the org membership commands when the user isn't in the org. - 404 tells a missing organization apart from a missing object and suggests the matching list command. The profile reaches Execute through a *client.Target in the command context, filled in by clientForProfile. An error a command already explained in its own words (the acl commands) is left alone; a plain prefix is kept. client.Explain is unchanged, so config validate keeps its one-line details. The integration suite's one-line assertions for 401, 403, 404 and 409 now accept the multi-line explanation. Signed-off-by: Tim Smith <tsmith84@proton.me>
A name the server quotes back (the actor in a 401 or 403 message) only goes into a suggested command when it is a plain Chef name; otherwise the profile's client_name or a placeholder is used, so a hostile server can't plant a shell command for the user to paste. The server's message has terminal escape sequences and control characters removed before it is printed. Signed-off-by: Tim Smith <tsmith84@proton.me>
Signed-off-by: Tim Smith <tsmith84@proton.me>
Signed-off-by: Tim Smith <tsmith84@proton.me>
tas50
force-pushed
the
errors-server-responses
branch
from
November 27, 2026 06:56
1811277 to
a30b4d8
Compare
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.
Server errors reached the user as cinc-api's raw
ErrorResponse.Error().Executenow printsclient.ExplainFor(err, target), which retells a 400, 401, 403, 404, 409, 413 or 5xx as what went wrong and what to do. It names the object (worked out from the request path), the organization, and the client, server, key and profile the command signed with, and gives a runnable command where one exists. The server's own message, status and request stay visible on a "The server said:" line.Invalid signature ...), unknown client or user (Failed to authenticate as ...), clock skew (... time stamp too far ...), or all three causes when the message is something else.<noun> acl show/<noun> acl grant.'<user>' not associated with organization '<org>'getsorg member add/org invite createinstead.Cannot find org X, erchef'sorganization 'X' does not exist.) from a missing object, and suggests the matchinglist/showcommand. A 404 on a collection under an object (/clients/X/keys) is reported as the object missing.The profile reaches
Executethrough a*client.Targetin the command context, filled in byclientForProfile. An error a command already rewrote (the acl commands'aclError) is left alone; a plainfmt.Errorf("x: %w")prefix is kept. The result wraps the original, soerrors.Is(err, cinc.ErrNotFound)etc. still work.client.Explainis unchanged, soconfig validatekeeps its one-line check details.Suggested commands are built only from local values (the profile, the request path, or a
<placeholder>); a name the server quotes back is used only if it matches^[A-Za-z0-9_.:-]+$, and the server's message has control characters and terminal escape sequences stripped before printing.The integration suite asserted one-line errors for 401, 403, 404 and 409 and
": <code>:"forwantStatus; those now accept the explanation (behStderr,hasStatus).make test-integrationpasses against cinc-server-ng.Before / after