can1357/oh-my-pi · error · LsError

invalid --time-style argument {} Possible values are: - [p

Error message

invalid --time-style argument {}
Possible values are:
  - [posix-]full-iso
  - [posix-]long-iso
  - [posix-]iso
  - [posix-]locale
  - +FORMAT (e.g., +%H:%M) for a 'date'-style format

For more information try --help

What it means

LsError::TimeStyleParseError is raised when the builtin `ls` receives a --time-style value it does not recognize. Accepted values are the GNU set: [posix-]full-iso, [posix-]long-iso, [posix-]iso, [posix-]locale, or a date-style +FORMAT string such as +%H:%M. The message enumerates all valid choices.

Source

Thrown at crates/pi-builtins/src/ls.rs:3711

		},
		_ => if 9 == .1.raw_os_error().unwrap_or(1) {
			format!("cannot open directory {}: Bad file descriptor", .0.quote())
		} else {
			format!("unknown io error: {}, '{:?}'", .0.quote(), .1)
		},
	})]
	IOErrorContext(PathBuf, std::io::Error, bool, bool),

	#[error("invalid --block-size argument '{0}'")]
	BlockSizeParseError(String),

	#[error("--dired and --zero are incompatible")]
	DiredAndZeroAreIncompatible,

	#[error("{}: not listing already-listed directory", .0.maybe_quote())]
	AlreadyListedError(PathBuf),

	#[error("invalid --time-style argument {}\nPossible values are:\n  - [posix-]full-iso\n  - [posix-]long-iso\n  - [posix-]iso\n  - [posix-]locale\n  - +FORMAT (e.g., +%H:%M) for a 'date'-style format\n\nFor more information try --help", .0.quote())]
	TimeStyleParseError(String),
}

impl LsError {
	fn code(&self) -> i32 {
		match self {
			Self::InvalidLineWidth(_) => 2,
			Self::IOError(_) => 1,
			Self::IOErrorContext(_, _, false, _) => 1,
			Self::IOErrorContext(_, _, true, _) => 2,
			Self::BlockSizeParseError(_) => 2,
			Self::DiredAndZeroAreIncompatible => 2,
			Self::AlreadyListedError(_) => 2,
			Self::TimeStyleParseError(_) => 2,
		}
	}
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Use one of the exact keywords: full-iso, long-iso, iso, locale (optionally prefixed with posix-)
  2. Ensure a custom format starts with +, e.g. --time-style=+%Y-%m-%d %H:%M
  3. Check the TIME_STYLE environment variable for values inherited from BSD/macOS conventions
  4. Run `ls --help` to confirm supported styles in this build

Example fix

// before
ls --time-style=longiso
// after
ls --time-style=long-iso
Defensive patterns

Strategy: validation

Validate before calling

const TIME_STYLES = new Set(['full-iso','long-iso','iso','locale',
  'posix-full-iso','posix-long-iso','posix-iso','posix-locale']);
if (timeStyle !== undefined && !TIME_STYLES.has(timeStyle) && !timeStyle.startsWith('+')) {
  throw new RangeError(`invalid --time-style '${timeStyle}'`);
}

Type guard

const isTimeStyle = (v: string): boolean =>
  /^(posix-)?(full-iso|long-iso|iso|locale)$/.test(v) || v.startsWith('+');

Try / catch

try {
  runLs(['--time-style=' + style, ...rest]);
} catch (e) {
  if (String(e).includes('invalid --time-style')) {
    runLs(['--time-style=long-iso', ...rest]); // safe default
  } else throw e;
}

Prevention

When it happens

Trigger: Running `ls --time-style=<bad>` where <bad> is a misspelled keyword (e.g. 'longiso' without the dash prefix... actually 'long-iso' is required), a bare keyword missing its posix- prefix variant handling, a +FORMAT without the leading +, or a format with invalid strftime specifiers context.

Common situations: Setting TIME_STYLE env var (via /etc/profile or ~/.bashrc) with a value from a different ls implementation (BSD ls uses different keywords), typos like 'iso-locale' or 'LONG-ISO', scripts copied between macOS (BSD ls) and GNU ls.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/78473c9000f865bc. Report an issue: GitHub.