charmbracelet/crush · warning
failed to get current working directory: %v
Error message
failed to get current working directory: %v
What it means
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.
Source
Thrown at internal/cmd/logs.go:30
"charm.land/log/v2"
"github.com/charmbracelet/colorprofile"
"github.com/charmbracelet/crush/internal/config"
"github.com/charmbracelet/x/term"
"github.com/nxadm/tail"
"github.com/spf13/cobra"
)
const defaultTailLines = 1000
var logsCmd = &cobra.Command{
Use: "logs",
Short: "View crush logs",
Long: `View the logs generated by Crush. This command allows you to see the log output for debugging and monitoring.`,
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)View on GitHub (pinned to 7944b8e522)
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.
Example fix
// before (missing registration)
RunE: func(cmd *cobra.Command, args []string) error { ... }
// after
cmd.Flags().String("cwd", "", "Working directory")
cmd.Flags().String("data-dir", "", "Data directory") Defensive patterns
Strategy: fallback
Validate before calling
// Go: guard flag lookups defensively
if f := cmd.Flags().Lookup("cwd"); f == nil {
cwd, _ = os.Getwd() // fallback
} Try / catch
cwd, err := cmd.Flags().GetString("cwd")
if err != nil {
cwd, _ = os.Getwd() // fall back to process working directory
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Custom builds or forks with modified command setup; calling the command programmatically in tests without registering flags; merge conflicts dropping Flags().String("cwd", ...) lines.
Related errors
- failed to get data directory: %v
- failed to get follow flag: %v
- failed to get tail 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/3d85eabf8bab1b30.
Report an issue: GitHub.