charmbracelet/crush · warning
failed to get tail flag: %v
Error message
failed to get tail flag: %v
What it means
The `crush logs` command reads the integer --tail flag via cmd.Flags().GetInt and wraps any failure with this message. GetInt errors only when the flag is not defined on the command; user-supplied bad integers are rejected earlier by cobra's flag parsing with a different error.
Source
Thrown at internal/cmd/logs.go:45
RunE: func(cmd *cobra.Command, args []string) error {
cwd, err := cmd.Flags().GetString("cwd")
if err != nil {
return fmt.Errorf("failed to get current working directory: %v", err)
}
dataDir, err := cmd.Flags().GetString("data-dir")
if err != nil {
return fmt.Errorf("failed to get data directory: %v", err)
}
follow, err := cmd.Flags().GetBool("follow")
if err != nil {
return fmt.Errorf("failed to get follow flag: %v", err)
}
tailLines, err := cmd.Flags().GetInt("tail")
if err != nil {
return fmt.Errorf("failed to get tail flag: %v", err)
}
log.SetLevel(log.DebugLevel)
log.SetOutput(os.Stdout)
if !term.IsTerminal(os.Stdout.Fd()) {
log.SetColorProfile(colorprofile.NoTTY)
}
cfg, err := config.Load(cwd, dataDir, false)
if err != nil {
return fmt.Errorf("failed to load configuration: %v", err)
}
logsFile := filepath.Join(cfg.Config().Options.DataDirectory, "logs", "crush.log")
_, err = os.Stat(logsFile)
if os.IsNotExist(err) {
log.Warn("Looks like you are not in a crush project. No logs found.")
return nil
}View on GitHub (pinned to 7944b8e522)
Solutions
- Reinstall/rebuild crush from an official source tree.
- If developing: register `cmd.Flags().Int("tail", ...)` in the logs command setup.
- Add a test that executes the command with all flags registered to catch wiring drift.
Example fix
// before
RunE queries: cmd.Flags().GetInt("tail") // not registered
// after
cmd.Flags().Int("tail", 100, "Number of lines to show from the end of the log") Defensive patterns
Strategy: fallback
Validate before calling
if f := cmd.Flags().Lookup("tail"); f == nil {
tailLines = 100 // sensible default
} Try / catch
tailLines, err := cmd.Flags().GetInt("tail")
if err != nil {
tailLines = 100
} Prevention
- Register integer flags with defaults in the command constructor.
- Centralize flag name constants.
- Run command smoke tests in CI to catch missing registrations.
- Distinguish parse errors (user input) from lookup errors (wiring) in handlers.
When it happens
Trigger: RunE querying "tail" while the --tail flag registration is missing (fork, partial refactor), or calling RunE programmatically on an unconfigured command.
Common situations: Custom builds where flag setup diverged from RunE; test code invoking RunE directly; merge conflict removing the registration line.
Related errors
- failed to get current working directory: %v
- failed to get data directory: %v
- failed to get follow flag: %v
- failed to get data directory: %v
- failed to get debug flag: %v
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/6f31b2e65d955108.
Report an issue: GitHub.