{"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/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/lib/index.mjs#L118-L154","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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."],"exampleFix":"// before (.env)\nH1B_INDEX_PATH=\n\n// after — either remove the line entirely, or give it a real value:\n# H1B_INDEX_PATH=            <- removed: use default\nH1B_INDEX_PATH=/data/h1b/index.db","handlingStrategy":"validation","validationCode":"const raw = process.env.H1B_INDEX_PATH;\nif (raw !== undefined && !String(raw).trim()) {\n  throw new Error(`H1B_INDEX_PATH is defined but empty; unset it or set a real path before starting`);\n}","typeGuard":"function hasValidIndexPath(env = process.env) {\n  const raw = env.H1B_INDEX_PATH;\n  return raw === undefined || (typeof raw === 'string' && raw.trim().length > 0);\n}","tryCatchPattern":"let file;\ntry {\n  file = indexPath();\n} catch (e) {\n  if (/H1B_INDEX_PATH is set but empty/.test(e.message)) {\n    console.error('Fix env: unset H1B_INDEX_PATH or provide a path');\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["environment","configuration","validation","path"],"backgroundTag":"invalid-env-var-value","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}