JanDeDobbeleer/oh-my-posh · error

--data-only and --data-derive contradict each other: one for

Error message

--data-only and --data-derive contradict each other: one forbids probing the environment, the other forces it

What it means

applyDataFile in the data CLI rejects a combination of mutually exclusive flags. `--data-only` forbids any environment probing while applying data-file overrides, whereas `--data-derive` forces probing even for recorded files. Supplying both is defined as a contradiction, so the call fails fast instead of silently preferring one flag.

Source

Thrown at src/cli/data.go:63

	}

	if data.Version < config.DataVersion {
		fmt.Fprintf(os.Stderr,
			"warning: %s has no recorder version marker; treating it as hand-written - it is neither hermetic nor deterministic, "+
				"segments left out of it still probe the live environment. Run `oh-my-posh config export data` to record a deterministic file.\n",
			dataPath)
	}

	if dataDerive && data.Version >= config.DataVersion {
		data.Segments = deriveRecordedSegments(data.Segments)
	}

	// --data-only and --data-derive are opposites: one forbids probing
	// entirely, the other forces it even for a recorded file. Asking for both
	// is a contradiction rather than a combination, so say so instead of
	// silently letting one win.
	if dataOnly && dataDerive {
		return errors.New("--data-only and --data-derive contradict each other: one forbids probing the environment, the other forces it")
	}

	flags.DataOnly = dataOnly

	return data.ApplyFlags(flags, changed)
}

// deriveRecordedSegments strips the RecordedSegment envelope back down to each
// segment's raw writer data, forcing Segment.restoreData to treat a recorded
// file the same way it treats a hand-written one: derive live state via
// writer.Enabled(), then overlay the pinned data, instead of the hermetic no-probe
// path. The caller only calls this once data.Version confirms every entry is an
// envelope, so decoding here does not need to guard against a flat entry.
func deriveRecordedSegments(segments map[string]json.RawMessage) map[string]json.RawMessage {
	derived := make(map[string]json.RawMessage, len(segments))

	for key, raw := range segments {
		var recorded config.RecordedSegment

View on GitHub (pinned to 0976794618)

Solutions

  1. Remove one of the two flags: pass --data-only if you want a pure replay with no probing, or --data-derive if you want forced derivation.
  2. Audit wrapper scripts/aliases so only one of the flags is ever emitted.
  3. In CI, ensure mutually exclusive flag variables cannot both evaluate to true before invoking the command.

Example fix

// before
flags := []string{"--data-only", "--data-derive", "--file", "state.json"}
// after
flags := []string{"--data-only", "--file", "state.json"} // or --data-derive, never both
Defensive patterns

Strategy: validation

Validate before calling

if dataOnly && dataDerive {
    return errors.New("choose either --data-only or --data-derive, not both")
}

Try / catch

if err := applyDataFile(path, flags, changed); err != nil {
    if strings.Contains(err.Error(), "contradict") {
        fmt.Fprintln(os.Stderr, "fix your flag combination: --data-only and --data-derive are mutually exclusive")
        os.Exit(2)
    }
    return err
}

Prevention

When it happens

Trigger: Calling applyDataFile (via the `data` command's apply path) with both dataOnly=true and dataDerive=true — e.g. `oh-my-posh data apply --data-only --data-derive --file state.json`, or a wrapper script that hardcodes both flags.

Common situations: Users assuming the flags are orthogonal and combining them 'to be safe'; shell aliases or wrapper scripts accumulating flags over time; CI configs where one flag comes from a variable that defaults to on.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/97745e7fc4bbeee0. Report an issue: GitHub.