can1357/oh-my-pi · error
--rounds must be a positive integer
Error message
--rounds must be a positive integer
What it means
runCompressCommand validates CLI options before doing any work. maxRounds (from --rounds, defaulting to DEFAULT_MAX_ROUNDS) must be a positive integer; otherwise it throws. This catches non-numeric, zero, negative, or fractional round counts that would make the rewrite loop meaningless or infinite.
Source
Thrown at packages/coding-agent/src/compress/index.ts:80
found.add(match);
matched += 1;
}
if (matched === 0) throw new Error(`No files matched "${pattern}"`);
continue;
}
const resolved = path.resolve(cwd, pattern);
const stat = await fs.stat(resolved).catch(() => undefined);
if (!stat?.isFile()) throw new Error(`Not a file: ${shortenPath(resolved)}`);
found.add(resolved);
}
return [...found].sort();
}
/** Compress every requested file through the rewrite/approve loop. */
export async function runCompressCommand(options: CompressCommandOptions): Promise<CompressResult> {
const maxRounds = options.maxRounds ?? DEFAULT_MAX_ROUNDS;
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
if (!Number.isInteger(maxRounds) || maxRounds <= 0) throw new Error("--rounds must be a positive integer");
if (!Number.isInteger(concurrency) || concurrency <= 0) throw new Error("--agents must be a positive integer");
if (options.inPlace && options.output) throw new Error("--in-place and --out are mutually exclusive");
// Paths and patterns follow the shell's cwd, as a file-taking CLI must; the project
// dir only scopes settings discovery for the sessions.
const invocationDir = process.cwd();
const cwd = getProjectDir();
const targets = await resolveCompressTargets(options.files, invocationDir);
if (targets.length === 0) throw new Error("No files to compress");
if (targets.length > 1 && !options.inPlace) {
throw new Error(`${targets.length} files matched; pass --in-place to rewrite them (--out takes a single file)`);
}
const abortController = new AbortController();
const abort = (): void => abortController.abort(new Error("Compress interrupted"));
process.once("SIGINT", abort);
process.once("SIGTERM", abort);
const progress = createProgressReporter("Compressing");
const emitToStdout = targets.length === 1 && !options.inPlace && options.output === undefined;View on GitHub (pinned to 9690622007)
Solutions
- Pass a positive integer, e.g. `--rounds 3`.
- Check the script/env that supplies the value (an unset shell variable expands to empty string).
- Omit the flag to use the default round count.
- Fix programmatic callers to pass an integer number, not a string or float.
Example fix
// before omp compress file.ts --rounds 0 // after omp compress file.ts --rounds 3
Defensive patterns
Strategy: validation
Validate before calling
function validRounds(v: unknown): v is number {
return typeof v === "number" && Number.isInteger(v) && v > 0;
}
if (!validRounds(maxRounds)) throw new Error("--rounds must be a positive integer"); Type guard
function isPositiveInt(v: unknown): v is number {
return typeof v === "number" && Number.isInteger(v) && v > 0;
} Try / catch
try {
await runCompressCommand({ ...options, maxRounds });
} catch (err) {
if (err instanceof Error && err.message === "--rounds must be a positive integer") {
process.stderr.write(`${err.message} (got: ${String(options.maxRounds)})\n`);
} else throw err;
} Prevention
- Always pass plain integers to --rounds (e.g. 1, 3, 5).
- Guard shell interpolation: `--rounds "${ROUNDS:-3}"`.
- Omit the flag to accept the default.
- Validate numeric CLI inputs with Number() before constructing options objects in scripts.
When it happens
Trigger: Invoking the compress command with `--rounds 0`, `--rounds -1`, `--rounds abc`, `--rounds 1.5`, or programmatically passing a non-integer options.maxRounds.
Common situations: Shell variable interpolation producing an empty/invalid value (`--rounds $UNSET_VAR`); copy-pasted config with 0 meaning 'unlimited'; scripts constructing options objects with float or string values.
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
- --agents must be a positive integer
- unknown file type: {value}
- invalid size: {value}
- 2
- invalid --block-size argument '{0}'
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/901dc727c867baed.
Report an issue: GitHub.