Skip to content

Explain the errors the Cinc server returns - #318

Merged
tas50 merged 4 commits into
mainfrom
errors-server-responses
Nov 27, 2026
Merged

tas50 merged 4 commits into
mainfrom
errors-server-responses

Conversation

@tas50

@tas50 tas50 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Server errors reached the user as cinc-api's raw ErrorResponse.Error(). Execute now prints client.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.

  • 401 is split on the server's message (same wording in erchef and cinc-server-ng): wrong key (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.
  • 403 names the action and object, plus <noun> acl show / <noun> acl grant. '<user>' not associated with organization '<org>' gets org member add / org invite create instead.
  • 404 distinguishes a missing organization (Cannot find org X, erchef's organization 'X' does not exist.) from a missing object, and suggests the matching list/show command. A 404 on a collection under an object (/clients/X/keys) is reported as the object missing.
  • 409 says what already exists (a POST's name isn't in the path, so it says "a node with that name").
  • 400 leads with the server's message. 413 and 5xx say whose problem it is and what to try.

The profile reaches Execute through a *client.Target in the command context, filled in by clientForProfile. An error a command already rewrote (the acl commands' aclError) is left alone; a plain fmt.Errorf("x: %w") prefix is kept. The result wraps the original, so errors.Is(err, cinc.ErrNotFound) etc. still work. client.Explain is unchanged, so config validate keeps 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>:" for wantStatus; those now accept the explanation (behStderr, hasStatus). make test-integration passes against cinc-server-ng.

Before / after

$ cinc node show web1
Error: cinc: GET /organizations/acme/nodes/web1: 404: Cannot load node web1
$ cinc node show web1
Error: we couldn't find node "web1" in organization "acme" on https://cinc.example.com.

The server said: Cannot load node web1 (404 from GET /organizations/acme/nodes/web1)

Check the spelling, or run `cinc node list` to see what's there.
$ cinc node list
Error: cinc: GET /organizations/acme/nodes: 401: Invalid signature for user or client 'tim' (check the client key and that the local clock is in sync)
$ cinc node list
Error: the Cinc server at https://cinc.example.com didn't accept the signature on the request from "tim".

The server said: Invalid signature for user or client 'tim' (401 from GET /organizations/acme/nodes)

cinc signs every request with a client key, a private key file the server checks against the public key it has on file for "tim". The server knows "tim", but the client key at /home/tim/.cinc/tim.pem (client_key in your "default" profile in /home/tim/.cinc/credentials) isn't the key it has for them. Here's how to fix it:
  - If you have the right key for "tim" somewhere else, point client_key at it.
  - If you don't, ask whoever runs your Cinc server for a new one: they can run `cinc client reregister tim` for a client, or `cinc user key create tim <key-name>` for a user. Save the .pem file they send you somewhere private and point client_key at it.
$ cinc role delete base -y
Error: cinc: DELETE /organizations/acme/roles/base: 403: missing delete permission
$ cinc role delete base -y
Error: "tim" isn't allowed to delete role "base" in organization "acme".

The server said: missing delete permission (403 from DELETE /organizations/acme/roles/base)

The server knows who you are; it's the permissions that stop you. Each object has an access list (ACL) saying who may create, read, update, delete, or grant on it. Ask an admin of the organization, or anyone with grant permission on role "base", to give "tim" delete permission. They can see who has access with `cinc role acl show base` and add you with `cinc role acl grant delete base --client tim` (use --user instead of --client if "tim" is a user).
$ cinc environment list
Error: cinc: GET /organizations/acme/environments: 404: Cannot find org acme
$ cinc environment list
Error: organization "acme" doesn't exist on https://cinc.example.com.

The server said: Cannot find org acme (404 from GET /organizations/acme/environments)

Everything on a Cinc server lives inside an organization, and the organization comes from the server URL in your "default" profile in /home/tim/.cinc/credentials (the part after /organizations/). Run `cinc org list` to see the organizations you can use, then fix the org name in that URL.

@tas50
tas50 force-pushed the errors-server-responses branch from 50dbcea to 59987fd Compare November 27, 2026 06:39
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
tas50 force-pushed the errors-server-responses branch from 1811277 to a30b4d8 Compare November 27, 2026 06:56
@tas50
tas50 merged commit 2652d99 into main Nov 27, 2026
6 checks passed
@tas50
tas50 deleted the errors-server-responses branch November 27, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant