Skip to content

fix: change errorf format to represent real value - #368

Merged
tksm merged 1 commit into
stern:masterfrom
Spuxy:fix-config-error-format
May 3, 2026
Merged

tksm merged 1 commit into
stern:masterfrom
Spuxy:fix-config-error-format

Conversation

@Spuxy

@Spuxy Spuxy commented May 2, 2026

Copy link
Copy Markdown
Contributor

cmd/cmd.go:443

and

cmd/cmd.go:450

both use fmt.Errorf("invalid value %q for %q in the config file: %v", value, name, err).
The first %q formats value, which is interface{} from a YAML decode (could be slice, int, bool, etc.), so %q is wrong.
I have changed that first %q to %v on both lines.

[stern ± fix-config-error-format] ◯ go run . --config /tmp/stern-bug-demo/config.yaml foo
Error: invalid value 60 for "since" in the config file: time: missing unit in duration "60"
Usage:
  stern pod-query [flags]

Flags:
  -A, --all-namespaces                  If present, tail across all namespaces. A specific namespace is ignored even if specified with --namespace.
      --burst int                       Maximum burst for throttle to the Kubernetes API server. Defaults to 0 (use client-go default). Ignored when --qps=-1.
      --color string                    Force set color output. 'auto':  colorize if tty attached, 'always': always colorize, 'never': never colorize. (default "auto")
      --completion string               Output stern command-line completion code for the specified shell. Can be 'bash', 'zsh' or 'fish'.
      --condition string                The condition to filter on: [condition-name[=condition-value]. The default condition-value is true. Match is case-insensitive. Currently only supported with --tail=0 or --no-follow.
      --config string                   Path to the stern config file (default "~/.config/stern/config.yaml")
...

Testing yaml file:

[stern ± fix-config-error-format] ◯ cat /tmp/stern-bug-demo/config.yaml
     File: /tmp/stern-bug-demo/config.yaml
   1 since: 60

@tksm tksm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍. Verified against the released stern (without fix) and a dist/stern built from this branch (with fix).

make build  # produces dist/stern from this branch

for bin in stern ./dist/stern; do
  echo "### $bin ($("$bin" --version | head -1))"
  for cfg in 'since: 60' 'since: true' $'tail:\n  - 1\n  - 2'; do
    printf '%s\n' "$cfg" > /tmp/cfg.yaml
    echo "--- $cfg"
    "$bin" --config /tmp/cfg.yaml foo 2>&1 | head -1
  done
  echo
done
### stern (version: 1.34.0)
--- since: 60
Error: invalid value '<' for "since" in the config file: time: missing unit in duration "60"
--- since: true
Error: invalid value %!q(bool=true) for "since" in the config file: time: invalid duration "true"
--- tail:
  - 1
  - 2
Error: invalid value ['\x01' '\x02'] for "tail" in the config file: strconv.ParseInt: parsing "[1 2]": invalid syntax

### ./dist/stern (version: dev)
--- since: 60
Error: invalid value 60 for "since" in the config file: time: missing unit in duration "60"
--- since: true
Error: invalid value true for "since" in the config file: time: invalid duration "true"
--- tail:
  - 1
  - 2
Error: invalid value [1 2] for "tail" in the config file: strconv.ParseInt: parsing "[1 2]": invalid syntax

@Spuxy Thanks for the fix!
Could you please rebase this PR? Once that's done, I'll merge it.

@Spuxy

Spuxy commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

Yep ill do

@Spuxy
Spuxy force-pushed the fix-config-error-format branch from 04249b3 to e2417d6 Compare May 3, 2026 07:33
@tksm
tksm merged commit 0d39b3f into stern:master May 3, 2026
1 check passed
@tksm

tksm commented May 3, 2026

Copy link
Copy Markdown
Contributor

Thank you for the PR!

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.

2 participants