Skip to content

cmd: colored error message in WrapCommandFuncForCobra (#7760) - #7768

Merged
francislavoie merged 3 commits into
caddyserver:masterfrom
u5surf:issue-7760
Jun 5, 2026
Merged

francislavoie merged 3 commits into
caddyserver:masterfrom
u5surf:issue-7760

Conversation

@u5surf

@u5surf u5surf commented May 25, 2026

Copy link
Copy Markdown
Contributor

Assistance Disclosure

I consulted Claude code for the issue, but I coded it myself because it is easy to fix, but Claude helped me to generate some code comments.

Fixes: #7760

WrapCommandFuncForCobra has not colored error messages. So We should wrap error messages with caddy.Log().Error.

@francislavoie francislavoie added the feature ⚙️ New feature or request label Jun 4, 2026
@francislavoie francislavoie added this to the v2.11.5 milestone Jun 4, 2026
@francislavoie

Copy link
Copy Markdown
Member

I think this is probably fine but it does sorta mean the error message is a bit less machine readable since it's not just plain text on the final line, but I think that's probably not a big deal.

Do you mind taking a screenshot of how it looks for you before and after? Thanks!

@u5surf

u5surf commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@francislavoie

Do you mind taking a screenshot of how it looks for you before and after?

I took screenshots to compare before to after.
before:
before
after:
after

@francislavoie
francislavoie merged commit d730df2 into caddyserver:master Jun 5, 2026
28 checks passed
earthlingdavey added a commit to smallhoursorg/motel that referenced this pull request Oct 2, 2026
Caddy v2.11.6 (caddyserver/caddy#7768) routes a command's error
through its logger instead of cobra's plain "Error:" line, so off a
terminal the message arrives as JSON with its quotes escaped and the
fixed-string match missed it. The box still refused the push for the
right reason; only the assertion's spelling changed.
cplieger added a commit to cplieger/docker-caddy that referenced this pull request Oct 3, 2026
Moves both Caddy pins (the xcaddy builder and the runtime donor) to v2.11.6
together, since the build refuses a version mismatch between them.

Caddy v2.11.5 changed how startup errors reach the log
(caddyserver/caddy#7768, open bug #7962): a config that fails to load now
logs a JSON record instead of a plain "Error:" line, and a file that cannot
be read or adapted prints nothing. CaddyStartupFailed matches both shapes.

certmagic v0.25.6 changed how many lines a failed attempt logs, which
silently moved CaddyCertIssuanceFailed's count threshold. Both cert rules
are replaced by CaddyCertManagementFailing, which fires when a subject has
a certmagic error and no success for it within an hour, held 15 minutes.

The smoke tests read each rule's selector from alerts/logql.yaml and run it
against real Caddy output, and the certmagic pin moves to v0.25.6.
jfilter added a commit to civico-de/civicrm-standalone-compose that referenced this pull request Oct 12, 2026
Since Caddy 2.11.6, `caddy run` exits 1 on a config error without printing
it: CLI errors go through the default logger, which during `run` still
points at the startup buffer (caddyserver/caddy#7768; fixed on master by
#8180, not yet released). The `caddy:2` tag moved to 2.11.6 on 2026-10-02,
so a misspelt name in PUBLIC_PROFILES stopped Caddy with no hint why, and
the weekly test failed with "unknown profile stops Caddy: expected '1',
got ''" because it looked for Caddy's own "File to import not found" line.

The startup script now checks that each profile has a file and names the
missing one on stderr before exiting 1, independent of Caddy's logging.

The test asserted only the log line, never the exit code. Under
`docker compose up` the restart policy hides it: compose reports the
crash-looping container as healthy, exits 0, and `compose ps` shows exit
code 0 while `docker inspect` shows 1. The check now runs the service once
with `docker compose run` and asserts both exit 1 and the message.

Measured with the check lines from tests/run.sh against the caddy service:
- old check: passes on caddy:2.11.4, fails on caddy:2 (2.11.7) as in CI
- new check: passes on caddy:2.11.4 and caddy:2 (2.11.7)
- guard removed: fails on both ("unknown profile is named")
- guard skips the profile instead of exiting: fails on both
  ("stops Caddy": exit 124 from the timeout)
- valid profiles (all five, and none) still start; shellcheck clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Make caddy validate -c errors more prominent

3 participants