Hmbown/CodeWhale · error · TypeError

Runtime API path segment must be a non-empty value

Error message

Runtime API path segment must be a non-empty value

What it means

segment() encodes identifiers (threadId, runId, workerId) into URL path segments and refuses null, undefined, or blank/whitespace-only values. This TypeError is thrown before any request is made, protecting against malformed URLs like /v1/threads//events.

Solutions

  1. Validate the identifier is a non-empty string before calling the API method.
  2. Trace where the ID comes from — a failed fetch or empty DB row is usually the root cause.
  3. For optional operations, check for the ID first and skip or surface a clearer domain error.

Example fix

// before
await client.getFleetWorker(runId, workerId);
// after
if (!runId || !workerId) throw new Error("runId and workerId are required");
await client.getFleetWorker(runId, workerId);
Defensive patterns

Strategy: validation

Validate before calling

function requireId(name, v) { if (v === null || v === undefined || String(v).trim() === "") throw new Error(`${name} is required`); return v; }
await client.getFleetWorker(requireId("runId", runId), requireId("workerId", workerId));

Type guard

const hasId = (v) => v !== null && v !== undefined && String(v).trim() !== "";

Try / catch

try { await client.getFleetRun(id); } catch (err) { if (err instanceof TypeError && err.message.includes("path segment")) throw new Error("missing run id — upstream record not loaded?"); throw err; }

Prevention

When it happens

Trigger: Calling startFleetRun, getFleetRun, listFleetWorkers, getFleetWorker, interruptWorker, or threadEvents with an undefined/null/empty identifier — e.g. a record that failed to load, or an ID taken from an unset variable.

Common situations: Destructuring an API result that returned undefined; IDs stored as empty strings in config; passing a numeric 0 that was coerced/lost; optional chaining silently yielding undefined.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/e972ac9536d6bbd3. Report an issue: GitHub.

Appendix: source

Thrown at npm/runtime-sdk/index.js:208

    }
    throw new RuntimeApiError(
      `Runtime API request failed (${response.status}) for ${method} ${path}`,
      errorOptions,
    );
  }
}

export function createRuntimeClient(options = {}) {
  return new CodeWhaleRuntimeClient(options);
}

function normalizeBaseUrl(value) {
  return value.endsWith("/") ? value : `${value}/`;
}

function segment(value) {
  if (value === null || value === undefined || String(value).trim() === "") {
    throw new TypeError("Runtime API path segment must be a non-empty value");
  }
  return encodeURIComponent(String(value));
}

function fleetEventPath(path, options) {
  const query = new URLSearchParams();
  if (options.after !== undefined && options.after !== null && String(options.after) !== "") {
    query.set("after", String(options.after));
  }
  if (options.limit !== undefined && options.limit !== null) {
    query.set("limit", String(options.limit));
  }
  const encoded = query.toString();
  if (!encoded) {
    return path;
  }
  return `${path}${path.includes("?") ? "&" : "?"}${encoded}`;
}

View on GitHub (pinned to 433685b202)