santifer/career-ops · error
Refusing to write the cover letter outside output/: (empty…
Error message
Refusing to write the cover letter outside output/: (empty path)
What it means
safeOutputPath in generate-cover-letter.mjs validates the caller-supplied --out / output_path before any file write: an empty, null, or whitespace-only path cannot be proven to live inside OUTPUT_ROOT, so it refuses with a fixed message rather than writing to an arbitrary location. All cover letters must land under output/.
Solutions
- Pass a real relative filename, e.g. `--out cover-letter.md` (it will be placed inside output/).
- In scripts, guard before invoking: `[ -n "$OUT" ] || { echo 'OUT is empty'; exit 1; }`.
- In JSON payloads, set output_path to a non-empty relative path like "output/cover.md".
Example fix
// before node generate-cover-letter.mjs --out "" // after node generate-cover-letter.mjs --out cover-letter-064.md
Defensive patterns
Strategy: validation
Validate before calling
if (!outPath || !String(outPath).trim()) { throw new Error('--out requires a non-empty path'); } Type guard
const hasOutputPath = (p) => p != null && String(p).trim() !== '';
Try / catch
try { const p = safeOutputPath(opts.out); } catch (e) { if (/\(empty path\)/.test(e.message)) { opts.out = defaultCoverLetterName(); } else throw e; } Prevention
- Always pass an explicit --out filename in scripts.
- Guard shell variables for emptiness before interpolation.
- Default output_path in payload builders to a generated filename instead of blank.
When it happens
Trigger: Calling safeOutputPath(null/undefined/'') or `generate-cover-letter.mjs --out ""`; a script variable holding the output path that resolved to empty; a JSON payload with output_path missing or set to "".
Common situations: An automation pipeline where `OUT_FILE=$(...)` produced an empty string; omitting --out while assuming a default exists; hand-built payload JSON where output_path was left blank.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Application Answers section has
- --from and --to must both be supplied together (or neither…
- --from ( ) must not be after --to ( ).
- H1B_INDEX_PATH is set but empty. Unset it to use the…
- Invalid page budget " ". Use a positive integer.
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/f66da0dd03240cf7.
Report an issue: GitHub.
Appendix: source
Thrown at generate-cover-letter.mjs:41
import { isMainModule } from "./lib/is-main-module.mjs";
const __dirname = dirname(fileURLToPath(import.meta.url));
const OUTPUT_ROOT = resolve(__dirname, "output");
/**
* Resolve a requested cover-letter output path.
*
* Paths that stay inside `output/` keep their relative subdirectory (the
* application-bundle layout `generate-pdf.mjs` already supports). Paths that
* would escape `output/` — `..` traversal or an absolute path outside it —
* are rejected instead of being silently flattened to `output/<basename>`.
*
* @param {string} raw - Caller-supplied --out / payload.output_path value.
* @returns {string} Absolute path inside OUTPUT_ROOT.
*/
export function safeOutputPath(raw) {
if (raw == null || String(raw).trim() === "") {
throw new Error("Refusing to write the cover letter outside output/: (empty path)");
}
const trimmed = String(raw).trim();
const asWritten = resolve(trimmed);
if (containedInOutput(asWritten)) return asWritten;
// Absolute paths and any `..` segment already chose a location; if that
// location is not inside output/, refuse instead of rewriting to a basename.
if (isAbsolute(trimmed) || /(^|[\\/])\.\.([\\/]|$)/.test(trimmed)) {
throw new Error(`Refusing to write the cover letter outside output/: ${raw}`);
}
// Bare filename or a relative path that is not already under output/
// (e.g. --out cover.pdf, or --out output/foo/bar.pdf from another cwd).
const posix = trimmed.replace(/\\/g, "/").replace(/^\.\//, "");
const relativeToRoot = posix === "output" || posix === "output/"
? ""
: posix.startsWith("output/")View on GitHub (pinned to aac998c7ed)