{"record":{"id":"e142af1c13aba02f","repo":"charmbracelet/crush","slug":"failed-to-get-data-directory-v","errorCode":null,"errorMessage":"failed to get data directory: %v","messagePattern":"failed to get data directory: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cmd/logs.go","lineNumber":35,"sourceCode":"\t\"github.com/nxadm/tail\"\n\t\"github.com/spf13/cobra\"\n)\n\nconst defaultTailLines = 1000\n\nvar logsCmd = &cobra.Command{\n\tUse:   \"logs\",\n\tShort: \"View crush logs\",\n\tLong:  `View the logs generated by Crush. This command allows you to see the log output for debugging and monitoring.`,\n\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","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/logs.go#L17-L53","documentation":"Same pattern as the --cwd lookup: `crush logs` fetches the --data-dir flag with GetString and wraps lookup failure with this message. GetString only errors when the flag does not exist on the command, so this signals a flag-registration/wiring problem rather than anything user-supplied.","triggerScenarios":"The logs command's RunE executes without `--data-dir` being registered (removed or renamed in a fork/build), or RunE is invoked programmatically on a partially constructed cobra.Command.","commonSituations":"Custom builds/forks with inconsistent flag setup; tests invoking RunE directly; accidental deletion of the flag registration during refactoring.","solutions":["Rebuild crush from the official source; do not use a patched binary with mismatched command wiring.","If developing: add `cmd.Flags().String(\"data-dir\", \"\", \"Data directory\")` to the logs command setup.","In tests, register flags (or use cmd.Flags().Lookup/MarkHidden checks) before calling RunE."],"exampleFix":"// before\nRunE: func(cmd *cobra.Command, args []string) error {\n    dataDir, err := cmd.Flags().GetString(\"data-dir\") // panics-free but errors: no such flag\n// after (in command init)\ncmd.Flags().String(\"data-dir\", \"\", \"Data directory\")","handlingStrategy":"fallback","validationCode":"if f := cmd.Flags().Lookup(\"data-dir\"); f == nil {\n    dataDir = defaultDataDir() // fallback to default location\n}","typeGuard":null,"tryCatchPattern":"dataDir, err := cmd.Flags().GetString(\"data-dir\")\nif err != nil {\n    dataDir = \"\" // let config.Load resolve its default\n}","preventionTips":["Define all flags in one init function per command.","Use shared constants for flag names.","Test commands programmatically only with fully registered flags.","Rebuild from clean source after patching."],"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"}