charmbracelet/crush · warning

failed to get data directory: %v

Error message

failed to get data directory: %v

What it means

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.

Source

Thrown at internal/cmd/logs.go:35

	"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)
		log.SetOutput(os.Stdout)
		if !term.IsTerminal(os.Stdout.Fd()) {
			log.SetColorProfile(colorprofile.NoTTY)
		}

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Rebuild crush from the official source; do not use a patched binary with mismatched command wiring.
  2. If developing: add `cmd.Flags().String("data-dir", "", "Data directory")` to the logs command setup.
  3. In tests, register flags (or use cmd.Flags().Lookup/MarkHidden checks) before calling RunE.

Example fix

// before
RunE: func(cmd *cobra.Command, args []string) error {
    dataDir, err := cmd.Flags().GetString("data-dir") // panics-free but errors: no such flag
// after (in command init)
cmd.Flags().String("data-dir", "", "Data directory")
Defensive patterns

Strategy: fallback

Validate before calling

if f := cmd.Flags().Lookup("data-dir"); f == nil {
    dataDir = defaultDataDir() // fallback to default location
}

Try / catch

dataDir, err := cmd.Flags().GetString("data-dir")
if err != nil {
    dataDir = "" // let config.Load resolve its default
}

Prevention

When it happens

Trigger: 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.

Common situations: Custom builds/forks with inconsistent flag setup; tests invoking RunE directly; accidental deletion of the flag registration during refactoring.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/e142af1c13aba02f. Report an issue: GitHub.