jackwener/OpenCLI · error · CliError
CONFIG
CONFIG
Error message
Missing ONES_BASE_URL
What it means
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.
Source
Thrown at clis/ones/common.js:10
/**
* ONES 旧版 Project API — 经 Browser Bridge 在已登录标签页内 fetch(携带 Cookie)。
* 文档:https://developer.ones.cn/zh-CN/docs/api/readme/
*/
import { CliError } from '@jackwener/opencli/errors';
export const API_PREFIX = '/project/api/project';
export function getOnesBaseUrl() {
const u = process.env.ONES_BASE_URL?.trim().replace(/\/+$/, '');
if (!u) {
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).');
}
return u;
}
export function onesApiUrl(apiPath) {
const base = getOnesBaseUrl();
const p = apiPath.replace(/^\/+/, '');
return `${base}${API_PREFIX}/${p}`;
}
/** 打开 ONES 根地址,确保后续 fetch 与页面同源、带上登录 Cookie */
export async function gotoOnesHome(page) {
await page.goto(getOnesBaseUrl(), { waitUntil: 'load' });
await page.wait(2);
}
/**
* 在页面内发起请求。默认带 credentials;若设置了 ONES_USER_ID + ONES_AUTH_TOKEN,则附加文档要求的 Header(与纯 Cookie 二选一或并存,取决于部署)。
*/
function buildHeaders(auth, includeJsonContentType) {
const ref = getOnesBaseUrl();View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before $ ones ref ABC-123 Error: Missing ONES_BASE_URL // after $ export ONES_BASE_URL=https://your-team.ones.cn $ ones ref ABC-123
Defensive patterns
Strategy: validation
Validate before calling
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'); Type guard
function hasOnesBaseUrl(env = process.env) { return typeof env.ONES_BASE_URL === 'string' && env.ONES_BASE_URL.trim().length > 0; } Try / catch
try { const base = getOnesBaseUrl(); } catch (e) { if (e.code === 'CONFIG') { console.error(e.message, '-', e.details ?? ''); process.exitCode = 1; } else throw e; } Prevention
- 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.
When it happens
Trigger: Running any ONES CLI command without ONES_BASE_URL exported, with it set to an empty string, or set to whitespace only.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/23a1f349a67b32ca.
Report an issue: GitHub.