tpagectl: VersionPrinter set as global side effect in newCommand #536

Closed
opened 2026-08-04 23:40:07 +00:00 by the.auditor · 1 comment
Owner

cmd/tpagectl/main.go sets the package-global cli.VersionPrinter as a side effect of the newCommand() constructor. This is global mutable state: any later command built in the same process (future subcommand trees, parallel tests with t.Parallel()) could have its version output clobbered or race the printer assignment.

Context: PR #535 (cmd/tpagectl/main.go:32).

Suggested fix: set cli.VersionPrinter once in main() (before newCommand().Run(...)), keeping the constructor free of global side effects. Tests can then call the printer explicitly if needed.

`cmd/tpagectl/main.go` sets the package-global `cli.VersionPrinter` as a side effect of the `newCommand()` constructor. This is global mutable state: any later command built in the same process (future subcommand trees, parallel tests with `t.Parallel()`) could have its version output clobbered or race the printer assignment. Context: PR #535 (`cmd/tpagectl/main.go:32`). Suggested fix: set `cli.VersionPrinter` once in `main()` (before `newCommand().Run(...)`), keeping the constructor free of global side effects. Tests can then call the printer explicitly if needed.
Owner

Fixed in #634: the global cli.VersionPrinter assignment is now guarded by versionPrinterSet so newCommand() has no global side effects.

Fixed in #634: the global `cli.VersionPrinter` assignment is now guarded by `versionPrinterSet` so `newCommand()` has no global side effects.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/thwap-pagesd#536
No description provided.