{"record":{"id":"9060d962eb973d07","repo":"santifer/career-ops","slug":"h1b-api-base-is-set-but-empty-unset-it-to-use-the","errorCode":null,"errorMessage":"H1B_API_BASE is set but empty. Unset it to use the default endpoint.","messagePattern":"H1B_API_BASE is set but empty\\. Unset it to use the default endpoint\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/lib/api.mjs","lineNumber":43,"sourceCode":"let resolvedBase;\n\nexport function apiBase() {\n  // Only a successful resolve is memoized; a bad value keeps throwing so the\n  // failure cannot be masked by an earlier call that happened to succeed.\n  if (resolvedBase === undefined) resolvedBase = resolveBase();\n  return resolvedBase;\n}\n\nfunction resolveBase() {\n  const raw = process.env.H1B_API_BASE;\n  // Absent means \"use the default\". Present but blank is a misconfiguration\n  // (an unset shell variable, an empty .env line, a CI secret that did not\n  // populate), and silently falling back would send someone's shortlist and\n  // their token to a host they believed they had replaced.\n  if (raw === undefined) return DEFAULT_BASE;\n  const trimmed = String(raw).trim();\n  if (!trimmed) {\n    throw new Error('H1B_API_BASE is set but empty. Unset it to use the default endpoint.');\n  }\n\n  let parsed;\n  try {\n    parsed = new URL(trimmed);\n  } catch {\n    throw new Error(`H1B_API_BASE is not a valid URL: ${trimmed}`);\n  }\n  if (parsed.username || parsed.password) {\n    // Undici refuses a credentialed Request anyway, and the value reaches\n    // stdout through the source field, so this would print a password.\n    throw new Error('H1B_API_BASE must not embed credentials.');\n  }\n  if (parsed.search || parsed.hash) {\n    // Paths are appended, so a query or fragment swallows them: the request\n    // would go to the base itself and answer about a company never asked for.\n    throw new Error('H1B_API_BASE must not contain a query string or a fragment.');\n  }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/lib/api.mjs#L25-L61","documentation":"resolveBase throws this when the H1B_API_BASE environment variable is defined but empty (or whitespace-only). The plugin deliberately refuses to fall back silently to the default endpoint, because an empty value usually means a configuration mistake (unset CI secret, blank .env line) and silently falling back would send the user's shortlist and token to a host they believed they had replaced.","triggerScenarios":"Calling any API function (e.g. getEmployerProfile) with H1B_API_BASE exported as an empty string: `export H1B_API_BASE=` in the shell, `H1B_API_BASE=` in .env, or a CI secret that did not populate.","commonSituations":"CI pipeline where the secret variable exists but has no value; a commented-out .env line leaving `H1B_API_BASE=` behind; copying a .env template without filling in the value.","solutions":["Set H1B_API_BASE to the intended https:// base URL, or unset it entirely (`unset H1B_API_BASE`) to use the default endpoint.","Remove the empty `H1B_API_BASE=` line from your .env file.","Fix the CI secret so it actually contains a value before the job runs."],"exampleFix":"// before (shell)\nexport H1B_API_BASE=\n// after\nunset H1B_API_BASE   # use default endpoint\n# or\nexport H1B_API_BASE=https://my-h1b-worker.example.com","handlingStrategy":"validation","validationCode":"if (process.env.H1B_API_BASE !== undefined && !process.env.H1B_API_BASE.trim()) {\n  throw new Error('H1B_API_BASE is set but empty; unset it or give it a value');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await getEmployerProfile(id);\n} catch (e) {\n  if (e.message.includes('H1B_API_BASE is set but empty')) {\n    console.error('Fix your environment: unset H1B_API_BASE or fill in a valid https URL.');\n  }\n}","preventionTips":["In .env files, comment out the whole line (`# H1B_API_BASE=...`) instead of leaving `H1B_API_BASE=`.","Validate required env vars at process startup, before any API call.","In CI, assert secrets are non-empty before the job step that uses them."],"tags":["env","configuration"],"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"}