{"record":{"id":"7d7af2d194424a3c","repo":"santifer/career-ops","slug":"h1b-index-path-is-set-but-empty-unset-it-to-use-t","errorCode":null,"errorMessage":"H1B_INDEX_PATH is set but empty. Unset it to use the default index location.","messagePattern":"H1B_INDEX_PATH is set but empty\\. Unset it to use the default index location\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/lib/index.mjs","lineNumber":136,"sourceCode":"    drain() {\n      trim();\n      return items;\n    },\n  };\n}\n\n/**\n * Where the index lives. H1B_INDEX_PATH relocates it (a shared read-only copy,\n * a scratch fixture in the test suite). Present-but-blank is a misconfiguration\n * rather than \"unset\", exactly as H1B_API_BASE treats it: silently falling back\n * would read an index the user believed they had replaced.\n */\nexport function indexPath() {\n  const raw = process.env.H1B_INDEX_PATH;\n  if (raw === undefined) return DEFAULT_INDEX;\n  const trimmed = String(raw).trim();\n  if (!trimmed) {\n    throw new Error('H1B_INDEX_PATH is set but empty. Unset it to use the default index location.');\n  }\n  return trimmed;\n}\n\n/** The sidecar install-h1b-index.mjs writes beside the index. */\nexport function metaPath(file = indexPath()) {\n  return `${file}.meta.json`;\n}\n\n/** Whether a local index is installed. Decides the backend, so it never throws on a missing file. */\nexport function hasIndex(file = indexPath()) {\n  return existsSync(file);\n}\n\nconst SHA256_RE = /^[0-9a-f]{64}$/;\nlet cachedDigest = null;\n\n/**","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/santifer/career-ops/blob/1696bec4d021768e7359f9aad6b329cba883da20/plugins/h1b-sponsor/lib/index.mjs#L118-L154","documentation":"indexPath() reads the H1B_INDEX_PATH environment variable. If the variable is defined but its value is empty or whitespace-only, the library cannot distinguish 'use default' from a misconfiguration, so it throws and tells you to unset the variable instead.","triggerScenarios":"Calling indexPath() (directly or via metaPath/indexFile or any lookup using the index) when the environment has H1B_INDEX_PATH set to '' or only spaces — e.g. `H1B_INDEX_PATH= node script.mjs` or `export H1B_INDEX_PATH=\"\"`.","commonSituations":"Docker/compose env entries like `H1B_INDEX_PATH=` in an .env file; a deploy template that comments out the value but leaves the key; a shell script doing `export H1B_INDEX_PATH=$SOME_VAR` where SOME_VAR is empty.","solutions":["Remove the H1B_INDEX_PATH line (or comment it out) from .env / the environment so the default index location is used.","If you do want a custom path, set it to a real path: H1B_INDEX_PATH=/path/to/h1b-index.","In shell scripts, guard expansion: `[ -n \"$VAR\" ] && export H1B_INDEX_PATH=\"$VAR\"`."],"exampleFix":"// before (.env)\nH1B_INDEX_PATH=\n// after\n# H1B_INDEX_PATH=/data/h1b/index.sqlite  (commented out = use default)","handlingStrategy":"validation","validationCode":"// before launching the tool:\nif (process.env.H1B_INDEX_PATH !== undefined && !process.env.H1B_INDEX_PATH.trim()) {\n  delete process.env.H1B_INDEX_PATH; // or throw with instructions\n}","typeGuard":"function hasUsableIndexPath(env = process.env) {\n  return env.H1B_INDEX_PATH === undefined || env.H1B_INDEX_PATH.trim() !== '';\n}","tryCatchPattern":"try {\n  const profile = await getEmployerProfile(id);\n} catch (e) {\n  if (e.message.startsWith('H1B_INDEX_PATH is set but empty')) {\n    console.error('Unset H1B_INDEX_PATH or give it a real path in .env.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Comment out unused env keys entirely instead of leaving `KEY=` blanks in .env.","In shell wrappers, only export the variable when the source variable is non-empty.","Include empty-vs-unset env checks in deployment templates and CI linting.","Remember the convention: unset = default location, set = custom path; there is no valid empty state."],"tags":["configuration","env-var","h1b"],"backgroundTag":"missing-env-var","analyzedSha":"1696bec4d021768e7359f9aad6b329cba883da20","analyzedAt":"2026-09-01T19:19:23.111Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}