{"record":{"id":"23a1f349a67b32ca","repo":"jackwener/OpenCLI","slug":"config","errorCode":"CONFIG","errorMessage":"Missing ONES_BASE_URL","messagePattern":"Missing ONES_BASE_URL","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/ones/common.js","lineNumber":10,"sourceCode":"/**\n * ONES 旧版 Project API — 经 Browser Bridge 在已登录标签页内 fetch（携带 Cookie）。\n * 文档：https://developer.ones.cn/zh-CN/docs/api/readme/\n */\nimport { CliError } from '@jackwener/opencli/errors';\nexport const API_PREFIX = '/project/api/project';\nexport function getOnesBaseUrl() {\n    const u = process.env.ONES_BASE_URL?.trim().replace(/\\/+$/, '');\n    if (!u) {\n        throw new CliError('CONFIG', 'Missing ONES_BASE_URL', 'Set ONES_BASE_URL to your deployment origin, e.g. https://your-team.ones.cn (no trailing slash).');\n    }\n    return u;\n}\nexport function onesApiUrl(apiPath) {\n    const base = getOnesBaseUrl();\n    const p = apiPath.replace(/^\\/+/, '');\n    return `${base}${API_PREFIX}/${p}`;\n}\n/** 打开 ONES 根地址，确保后续 fetch 与页面同源、带上登录 Cookie */\nexport async function gotoOnesHome(page) {\n    await page.goto(getOnesBaseUrl(), { waitUntil: 'load' });\n    await page.wait(2);\n}\n/**\n * 在页面内发起请求。默认带 credentials；若设置了 ONES_USER_ID + ONES_AUTH_TOKEN，则附加文档要求的 Header（与纯 Cookie 二选一或并存，取决于部署）。\n */\nfunction buildHeaders(auth, includeJsonContentType) {\n    const ref = getOnesBaseUrl();","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/ones/common.js#L1-L28","documentation":"getOnesBaseUrl reads ONES_BASE_URL from the environment, trims it and strips trailing slashes; if the variable is unset or empty it throws a CliError with code CONFIG explaining that the deployment origin must be configured. All ONES API calls (base, gotoOnesHome, ref) go through this function, so nothing works without it.","triggerScenarios":"Running any ONES CLI command without ONES_BASE_URL exported, with it set to an empty string, or set to whitespace only.","commonSituations":"Fresh install where the setup docs' `export ONES_BASE_URL=...` step was skipped, running in a new shell/tmux session where the env var was not persisted, or CI environments missing the secret.","solutions":["Export ONES_BASE_URL to your deployment origin, e.g. `export ONES_BASE_URL=https://your-team.ones.cn` (no trailing slash).","Persist it in your shell profile (~/.bashrc, ~/.zshrc) so new sessions inherit it.","In CI, add ONES_BASE_URL as a secret/environment variable in the pipeline config."],"exampleFix":"// before\n$ ones ref ABC-123\nError: Missing ONES_BASE_URL\n// after\n$ export ONES_BASE_URL=https://your-team.ones.cn\n$ ones ref ABC-123","handlingStrategy":"validation","validationCode":"if (!process.env.ONES_BASE_URL?.trim()) throw new Error('ONES_BASE_URL is not set; export ONES_BASE_URL=https://your-team.ones.cn');","typeGuard":"function hasOnesBaseUrl(env = process.env) { return typeof env.ONES_BASE_URL === 'string' && env.ONES_BASE_URL.trim().length > 0; }","tryCatchPattern":"try { const base = getOnesBaseUrl(); } catch (e) { if (e.code === 'CONFIG') { console.error(e.message, '-', e.details ?? ''); process.exitCode = 1; } else throw e; }","preventionTips":["Export ONES_BASE_URL in your shell profile so every session has it.","Add the variable to CI secrets/environment configuration.","Use ${ONES_BASE_URL:?not set} in scripts to fail fast with a clear message."],"tags":["config","env","missing-env-var"],"backgroundTag":"missing-env-var","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}