can1357/oh-my-pi · error · LsError

invalid --block-size argument '{0}'

Error message

invalid --block-size argument '{0}'

What it means

LsError::BlockSizeParseError is raised by the builtin `ls` when the value passed to --block-size cannot be parsed as a valid size (a number optionally followed by a unit suffix like K/M/G). The library mirrors GNU coreutils behavior, which rejects malformed SIZE strings before any listing happens. It is a pure argument-validation error, not an I/O failure.

Source

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

		ErrorKind::NotADirectory => format!("cannot access {}: Not a directory", .0.quote()),
		ErrorKind::NotFound => format!("cannot access {}: No such file or directory", .0.quote()),
		ErrorKind::PermissionDenied => match .1.raw_os_error().unwrap_or(1) {
			1 => format!("cannot access {}: Operation not permitted", .0.quote()),
			_ => if *.3 {
				format!("cannot open directory {}: Permission denied", .0.quote())
			} else {
				format!("cannot open file {}: Permission denied", .0.quote())
			},
		},
		_ => 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,

View on GitHub (pinned to 9690622007)

Solutions

  1. Pass a valid size: an integer optionally followed by K, M, G, T, P, E, Z, Y (e.g. --block-size=1M)
  2. Check for typos or stray characters in the flag value (`echo [-n "$BLOCK_SIZE"]` to spot hidden whitespace)
  3. Omit --block-size entirely to use the default block sizing
  4. If the value comes from an env var like BLOCK_SIZE or POSIXLY-correct wrappers, verify its contents

Example fix

// before
ls --block-size=1OMB
// after
ls --block-size=1M
Defensive patterns

Strategy: validation

Validate before calling

const VALID = /^\d+(?:[KMGTPEZY](?:B)?)?$/i;
if (blockSize !== undefined && !VALID.test(blockSize)) {
  throw new RangeError(`invalid --block-size '${blockSize}': use e.g. 1, 512, 1M`);
}

Type guard

const isBlockSize = (v: string): boolean => /^\d+([KMGTPEZY]B?)?$/i.test(v);

Try / catch

try {
  await Bun.$`ls --block-size=${bs} ${dir}`.quiet().nothrow();
} catch (e) {
  if (String(e).includes('invalid --block-size')) { /* fix arg and retry */ }
  throw e;
}

Prevention

When it happens

Trigger: Running the ls builtin with a --block-size value that is non-numeric, empty, has an unknown unit suffix (e.g. '12Q'), or a malformed combination like 'K1024'.

Common situations: Hand-typed CLI flags with typos ('--block-size=1OMB' instead of '1MB'), shell variables expanding to empty or whitespace, scripts ported between tools with different size-suffix conventions.

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/4830d3c61dd11cef. Report an issue: GitHub.