{"record":{"id":"3d85eabf8bab1b30","repo":"charmbracelet/crush","slug":"failed-to-get-current-working-directory-v","errorCode":null,"errorMessage":"failed to get current working directory: %v","messagePattern":"failed to get current working directory: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cmd/logs.go","lineNumber":30,"sourceCode":"\n\t\"charm.land/log/v2\"\n\t\"github.com/charmbracelet/colorprofile\"\n\t\"github.com/charmbracelet/crush/internal/config\"\n\t\"github.com/charmbracelet/x/term\"\n\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)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/logs.go#L12-L48","documentation":"The `crush logs` command reads its --cwd flag via cmd.Flags().GetString(\"cwd\") and wraps any failure with this message. In practice this only fails if the flag was not registered on the command (programming/wiring mistake) or the value cannot be parsed as a string, since a defined string flag essentially never errors on lookup.","triggerScenarios":"Running a build of crush where the logs command's flag registration was removed or renamed but RunE still queries \"cwd\"; manually invoking the command's RunE with a bare cobra.Command lacking the flag.","commonSituations":"Custom builds or forks with modified command setup; calling the command programmatically in tests without registering flags; merge conflicts dropping Flags().String(\"cwd\", ...) lines.","solutions":["Rebuild/reinstall crush from a clean checkout — this indicates a wiring bug, not user error.","If developing: ensure `cmd.Flags().String(\"cwd\", ...)` is called before RunE executes.","If testing programmatically, register the flag or use cmd.Flags().Set before invoking RunE."],"exampleFix":"// before (missing registration)\nRunE: func(cmd *cobra.Command, args []string) error { ... }\n// after\ncmd.Flags().String(\"cwd\", \"\", \"Working directory\")\ncmd.Flags().String(\"data-dir\", \"\", \"Data directory\")","handlingStrategy":"fallback","validationCode":"// Go: guard flag lookups defensively\nif f := cmd.Flags().Lookup(\"cwd\"); f == nil {\n    cwd, _ = os.Getwd() // fallback\n}","typeGuard":null,"tryCatchPattern":"cwd, err := cmd.Flags().GetString(\"cwd\")\nif err != nil {\n    cwd, _ = os.Getwd() // fall back to process working directory\n}","preventionTips":["Register every flag queried in RunE during command setup.","Add a smoke test that executes each command with its flags.","Prefer official builds to avoid wiring drift.","Keep flag names in constants shared between registration and lookup."],"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"}