Skip to content

Explain credentials file and profile errors for new users - #319

Merged
tas50 merged 1 commit into
mainfrom
errors-config
Nov 27, 2026
Merged

tas50 merged 1 commit into
mainfrom
errors-config

Conversation

@tas50

@tas50 tas50 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Errors about the credentials file and its profiles now name the profile and file involved, say what the setting is for, and show the line or command that fixes it. Same approach as #317, scaled to each problem: a missing flag gets a sentence and an example; a concept (client name, organization, credentials file) gets a short explanation and the fix.

How

config.Load records each profile's section name, file path and which server URL key it used (cinc_server_url or chef_server_url) in unexported fields, so Profile.Validate can name them without the command layer threading context through. A profile built in memory falls back to "this profile". The messages live in cli/config/errors.go. Wrapped errors still match ErrMissingServerURL, fs.ErrNotExist, fs.ErrPermission and toml.ParseError via errors.Is/As.

behStderrLine (integration) now accepts a multi-line message. It still fails on a second Error: or a usage dump. make test-integration passes.

Before / after

Missing client_name:

Before: Error: config: profile is missing client_name
After:  Error: your "default" profile in /home/you/.cinc/credentials doesn't set client_name.

        Every request cinc sends to your Cinc server is signed as a particular client, usually your username or a node's name, and client_name says which one. Add it to the profile, for example:
          [default]
          client_name = "your-name"
        Or run `cinc config create` to set the profile up again.

Server URL with no organization (names the key the file actually uses):

Before: Error: config: cinc: server URL "https://cinc.example.com" must end with /organizations/<org>
After:  Error: the server URL in your "default" profile in /home/you/.cinc/credentials, https://cinc.example.com, doesn't say which organization to use.

        A Cinc server can host several organizations, and every request goes to one of them, so chef_server_url has to end with /organizations/<org>. For example:
          [default]
          chef_server_url = "https://cinc.example.com/organizations/your-org"
        If you're not sure of your organization's name, ask whoever runs your Cinc server.

Malformed file:

Before: Error: config: we couldn't read /home/you/.cinc/credentials: toml: line 2 (last key "default.client_name"): expected value but found "tim" instead
After:  Error: we couldn't read the credentials file at /home/you/.cinc/credentials: line 2 isn't valid TOML (expected value but found "tim" instead).

        Each profile in the file starts with its name in square brackets, followed by one setting per line, with text values in double quotes:
          [default]
          cinc_server_url = "https://cinc.example.com/organizations/acme"
          client_name     = "tim"
          client_key      = "~/.cinc/tim.pem"
        Fix line 2 and try again.

Unknown profile:

Before: Error: config: unknown profile "prod"
After:  Error: there's no "prod" profile in /home/you/.cinc/credentials. The profiles it has are default, staging.

        Pick one of those with --profile, or run `cinc config create --profile prod` to add a "prod" profile.

When the name came from CINC_PROFILE/CHEF_PROFILE, the message says so and suggests changing that variable.

Missing --config file:

Before: Error: config: open ./nope: no such file or directory
After:  Error: there's no credentials file at ./nope.

        The credentials file holds the profiles cinc uses to reach your Cinc server. Check the path, or run `cinc config create --config ./nope` to create one there.

No credentials yet, no terminal:

Before: Error: no credentials yet at /home/you/.cinc/credentials — run `cinc config create` to set one up
After:  Error: you haven't set up your credentials yet, so we don't know which Cinc server to talk to or who you are there.

        cinc keeps that in a credentials file, /home/you/.cinc/credentials, which doesn't exist yet. To create it:
          - Run `cinc config create` in a terminal, and it'll ask for each setting.
          - Or pass everything as flags, which works in scripts too:
              cinc config create --server-url https://cinc.example.com/organizations/<org> --client-name <name> --client-key <path-to-key.pem>
        If you don't know your server URL or client name, or don't have a key, ask whoever runs your Cinc server.

config create flags:

Before: Error: cinc: --client-key is required
After:  Error: we need the path to the client key for "tim" to set up this profile. That's the private key file (a .pem file) your Cinc server made for "tim", and cinc signs every request with it. Pass it with --client-key, for example --client-key ~/.cinc/tim.pem. If you don't have the key, ask whoever runs your Cinc server to create one for "tim".

config validate check details:

Before: ✗ Server URL is valid: cinc: server URL "https://cinc.example.com" must end with /organizations/<org>
        ✗ Client key file is readable: cinc: read key file: open /home/you/.cinc/tim.pem: no such file or directory
After:  ✗ Server URL is valid: https://cinc.example.com doesn't say which organization to use. Add /organizations/<org> to the end, like https://cinc.example.com/organizations/your-org
        ✗ Client key file is readable: there's no file at /home/you/.cinc/tim.pem. Point client_key at this client's private key (.pem) file

A multi-line detail, such as a parse error, is indented under its check.

Also changed

  • Missing client_key, missing server URL, unparseable server URL, ValidateSiteURL, Supermarket identity (dropped an em dash), empty profile name, home directory lookup, unreadable file (chmod 600 hint), and write/stat/mkdir/chmod/encode failures in WriteProfile.
  • Knife credentials migration says which file and profile are at fault and that nothing was written. CheckChef names the bad line.
  • cinc explore --profile <unknown> lists the profiles there are.
  • Other config validate details: client_name, client_key, endpoint, ssl_verify_mode (shows the bad value and the leading colon), DNS failure, empty file.

Errors about the credentials file and its profiles now say which profile
and file are involved, what the setting is for, and the line or command
that fixes it, instead of terse fragments like "config: profile is
missing client_name".

Load records each profile's section name, file and server URL key, so
Profile.Validate can name them without the command layer passing context
down. Wrapped errors still match ErrMissingServerURL, fs.ErrNotExist and
toml.ParseError with errors.Is/As.

Covers missing client_name/client_key, a server URL with no organization
or no scheme, unknown profiles (listing the ones that exist and the env
var that picked the name), missing/unreadable/malformed credentials
files (with the TOML line at fault), write failures, config create's
missing flags, the no-credentials-yet message, config validate's check
details, knife credentials migration, and explore's unknown --profile.

behStderrLine now allows a multi-line message, still failing on a second
"Error:" or a usage dump.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 merged commit 98ae417 into main Nov 27, 2026
6 checks passed
@tas50
tas50 deleted the errors-config branch November 27, 2026 06:36
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