{"record":{"id":"6f31b2e65d955108","repo":"charmbracelet/crush","slug":"failed-to-get-tail-flag-v","errorCode":null,"errorMessage":"failed to get tail flag: %v","messagePattern":"failed to get tail flag: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cmd/logs.go","lineNumber":45,"sourceCode":"\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tcwd, err := cmd.Flags().GetString(\"cwd\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get current working directory: %v\", err)\n\t\t}\n\n\t\tdataDir, err := cmd.Flags().GetString(\"data-dir\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get data directory: %v\", err)\n\t\t}\n\n\t\tfollow, err := cmd.Flags().GetBool(\"follow\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get follow flag: %v\", err)\n\t\t}\n\n\t\ttailLines, err := cmd.Flags().GetInt(\"tail\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get tail flag: %v\", err)\n\t\t}\n\n\t\tlog.SetLevel(log.DebugLevel)\n\t\tlog.SetOutput(os.Stdout)\n\t\tif !term.IsTerminal(os.Stdout.Fd()) {\n\t\t\tlog.SetColorProfile(colorprofile.NoTTY)\n\t\t}\n\n\t\tcfg, err := config.Load(cwd, dataDir, false)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to load configuration: %v\", err)\n\t\t}\n\t\tlogsFile := filepath.Join(cfg.Config().Options.DataDirectory, \"logs\", \"crush.log\")\n\t\t_, err = os.Stat(logsFile)\n\t\tif os.IsNotExist(err) {\n\t\t\tlog.Warn(\"Looks like you are not in a crush project. No logs found.\")\n\t\t\treturn nil\n\t\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/logs.go#L27-L63","documentation":"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.","triggerScenarios":"RunE querying \"tail\" while the --tail flag registration is missing (fork, partial refactor), or calling RunE programmatically on an unconfigured command.","commonSituations":"Custom builds where flag setup diverged from RunE; test code invoking RunE directly; merge conflict removing the registration line.","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."],"exampleFix":"// before\nRunE queries: cmd.Flags().GetInt(\"tail\") // not registered\n// after\ncmd.Flags().Int(\"tail\", 100, \"Number of lines to show from the end of the log\")","handlingStrategy":"fallback","validationCode":"if f := cmd.Flags().Lookup(\"tail\"); f == nil {\n    tailLines = 100 // sensible default\n}","typeGuard":null,"tryCatchPattern":"tailLines, err := cmd.Flags().GetInt(\"tail\")\nif err != nil {\n    tailLines = 100\n}","preventionTips":["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."],"tags":["cli","cobra","flags"],"backgroundTag":"missing-flag-registration","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}