Skip to content

Rename die to dief - #62

Merged
korya merged 1 commit into
masterfrom
korya-refactor-dief
Aug 7, 2026
Merged

korya merged 1 commit into
masterfrom
korya-refactor-dief

Conversation

@korya

@korya korya commented Aug 7, 2026 •

Copy link
Copy Markdown
Owner

Problem

die takes a format string and variadic arguments but carried no f, so nothing at the call site distinguished it from a function taking a literal message.

die(71, "Invalid value for --log-level flag: %q", levelStr)

The standard library settles this with a suffix — Printf, Fatalf, Errorf. Without it, a reader has to open the definition to know whether the first string is a format, which matters because passing untrusted text containing a % to a format-taking function silently produces %!d(MISSING) in the output.

Solution

Rename to dief.

Before / after:

func die(rc int, format string, args ...interface{})    // is the string a format?
func dief(rc int, format string, args ...interface{})   // yes

Seven call sites renamed alongside the definition, plus a one-line doc comment on what the function does. No behaviour change — format strings, exit codes and output are untouched.

Verified by exercising every exit code the function produces:

Invocation Exit
unreachable host 93
--log-level trace 71
--maphost garbage 71
--assert-body '[bad' 71
-X 'BAD METHOD' 91
--nope 103

Coverage stays at 100.0%. No visual change — headless CLI.

🤖 Generated with Claude Code

Base automatically changed from korya-fix-regex-panic to master August 7, 2026 22:19
@korya
korya force-pushed the korya-refactor-dief branch from 74c0d5a to ac750bc Compare August 7, 2026 22:22
@korya
korya marked this pull request as ready for review August 7, 2026 22:23
die takes a format string and variadic arguments but carried no f, so nothing at the call site
distinguished it from a function taking a literal message. The standard library settles this with a
suffix -- Printf, Fatalf, Errorf -- and following it means a reader can tell which of these is safe
with untrusted text containing a percent sign.

Renames the function and its seven call sites. No behaviour change: the format strings, exit codes
and output are untouched, which the exit-code tests and the 100.0% coverage confirm.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP
@korya
korya force-pushed the korya-refactor-dief branch from ac750bc to 8bf824f Compare August 7, 2026 22:25
@korya
korya merged commit 4ffe282 into master Aug 7, 2026
1 check passed
@korya
korya deleted the korya-refactor-dief branch August 7, 2026 22:26
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