santifer/career-ops · error · Error
H1B_INDEX_PATH is set but empty. Unset it to use the…
Error message
H1B_INDEX_PATH is set but empty. Unset it to use the default index location.
What it means
indexPath() resolves the on-disk location of the H1B sponsor index from the H1B_INDEX_PATH environment variable, falling back to DEFAULT_INDEX when the variable is undefined. The library deliberately treats a variable that is defined but empty (or whitespace-only) as a configuration mistake rather than silently falling back, because an empty override usually means a shell script or .env file exported the variable without a value and the user's intent is ambiguous. It throws synchronously on every call, so any index read or write fails fast until the variable is fixed.
Solutions
- Unset the variable entirely so the default index location is used: delete 'H1B_INDEX_PATH=' from .env or run 'unset H1B_INDEX_PATH' in the shell/session.
- If a custom location is intended, set it to a non-empty path, e.g. H1B_INDEX_PATH=/var/lib/h1b/index.mjs (or the directory/file your install-h1b-index.mjs run produced).
- In CI/containers, remove the empty env entry (docker-compose: delete the line; GitHub Actions: drop the env: H1B_INDEX_PATH: '' mapping) instead of leaving it blank.
- If you cannot change the environment, pre-validate before launching: fail early with a clear message when the variable is defined but trim() is empty.
Example fix
// before (.env) H1B_INDEX_PATH= // after — either remove the line entirely, or give it a real value: # H1B_INDEX_PATH= <- removed: use default H1B_INDEX_PATH=/data/h1b/index.db
Defensive patterns
Strategy: validation
Validate before calling
const raw = process.env.H1B_INDEX_PATH;
if (raw !== undefined && !String(raw).trim()) {
throw new Error(`H1B_INDEX_PATH is defined but empty; unset it or set a real path before starting`);
} Type guard
function hasValidIndexPath(env = process.env) {
const raw = env.H1B_INDEX_PATH;
return raw === undefined || (typeof raw === 'string' && raw.trim().length > 0);
} Try / catch
let file;
try {
file = indexPath();
} catch (e) {
if (/H1B_INDEX_PATH is set but empty/.test(e.message)) {
console.error('Fix env: unset H1B_INDEX_PATH or provide a path');
process.exit(2);
}
throw e;
} Prevention
- In .env templates, comment out optional overrides (prefix with #) instead of shipping them as empty assignments.
- Validate env config at process startup with a small config-check step so the failure happens before any work.
- In shell wrappers, use ${VAR:+...} expansion or explicit -z checks to avoid exporting empty values.
- In CI, never map a secret to an env var unless the secret is required and populated.
When it happens
Trigger: Calling indexPath() (directly or via any function that opens the index, e.g. search or getEmployerProfile) when process.env.H1B_INDEX_PATH is exported as an empty string ('H1B_INDEX_PATH=' in .env, 'export H1B_INDEX_PATH=""' in a shell, or a CI secret left blank). Whitespace-only values (' ') hit the same branch after trim().
Common situations: A .env template line like H1B_INDEX_PATH= that was never filled in; a docker-compose/CI env entry set to an empty secret; a wrapper script that does H1B_INDEX_PATH="${SOME_VAR}" where SOME_VAR is unset under set -u avoidance patterns; a user who tried to 'reset to default' by clearing the value instead of unsetting the variable.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- capacity must be a finite number >= 1, got
- NOTION_ACCESS_TOKEN is not set (.env) — the Notion plugin…
- OPENROUTER_API_KEY not found. Copy .env.example to .env and…
- ratePerMin must be a finite number > 0, got
- Refusing to write the cover letter outside output/: (empty…
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/7d7af2d194424a3c.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/h1b-sponsor/lib/index.mjs:136
drain() {
trim();
return items;
},
};
}
/**
* Where the index lives. H1B_INDEX_PATH relocates it (a shared read-only copy,
* a scratch fixture in the test suite). Present-but-blank is a misconfiguration
* rather than "unset", exactly as H1B_API_BASE treats it: silently falling back
* would read an index the user believed they had replaced.
*/
export function indexPath() {
const raw = process.env.H1B_INDEX_PATH;
if (raw === undefined) return DEFAULT_INDEX;
const trimmed = String(raw).trim();
if (!trimmed) {
throw new Error('H1B_INDEX_PATH is set but empty. Unset it to use the default index location.');
}
return trimmed;
}
/** The sidecar install-h1b-index.mjs writes beside the index. */
export function metaPath(file = indexPath()) {
return `${file}.meta.json`;
}
/** Whether a local index is installed. Decides the backend, so it never throws on a missing file. */
export function hasIndex(file = indexPath()) {
return existsSync(file);
}
const SHA256_RE = /^[0-9a-f]{64}$/;
let cachedDigest = null;
/**View on GitHub (pinned to aac998c7ed)