{"record":{"id":"e972ac9536d6bbd3","repo":"Hmbown/CodeWhale","slug":"runtime-api-path-segment-must-be-a-non-empty-value","errorCode":null,"errorMessage":"Runtime API path segment must be a non-empty value","messagePattern":"Runtime API path segment must be a non-empty value","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"npm/runtime-sdk/index.js","lineNumber":208,"sourceCode":"    }\n    throw new RuntimeApiError(\n      `Runtime API request failed (${response.status}) for ${method} ${path}`,\n      errorOptions,\n    );\n  }\n}\n\nexport function createRuntimeClient(options = {}) {\n  return new CodeWhaleRuntimeClient(options);\n}\n\nfunction normalizeBaseUrl(value) {\n  return value.endsWith(\"/\") ? value : `${value}/`;\n}\n\nfunction segment(value) {\n  if (value === null || value === undefined || String(value).trim() === \"\") {\n    throw new TypeError(\"Runtime API path segment must be a non-empty value\");\n  }\n  return encodeURIComponent(String(value));\n}\n\nfunction fleetEventPath(path, options) {\n  const query = new URLSearchParams();\n  if (options.after !== undefined && options.after !== null && String(options.after) !== \"\") {\n    query.set(\"after\", String(options.after));\n  }\n  if (options.limit !== undefined && options.limit !== null) {\n    query.set(\"limit\", String(options.limit));\n  }\n  const encoded = query.toString();\n  if (!encoded) {\n    return path;\n  }\n  return `${path}${path.includes(\"?\") ? \"&\" : \"?\"}${encoded}`;\n}","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/npm/runtime-sdk/index.js#L190-L226","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the identifier is a non-empty string before calling the API method.","Trace where the ID comes from — a failed fetch or empty DB row is usually the root cause.","For optional operations, check for the ID first and skip or surface a clearer domain error."],"exampleFix":"// before\nawait client.getFleetWorker(runId, workerId);\n// after\nif (!runId || !workerId) throw new Error(\"runId and workerId are required\");\nawait client.getFleetWorker(runId, workerId);","handlingStrategy":"validation","validationCode":"function requireId(name, v) { if (v === null || v === undefined || String(v).trim() === \"\") throw new Error(`${name} is required`); return v; }\nawait client.getFleetWorker(requireId(\"runId\", runId), requireId(\"workerId\", workerId));","typeGuard":"const hasId = (v) => v !== null && v !== undefined && String(v).trim() !== \"\";","tryCatchPattern":"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; }","preventionTips":["Validate identifiers at the point they are obtained (fetch, DB row, CLI arg), not at the API call.","Use TypeScript non-optional types for IDs to catch undefined at compile time.","Fail with a domain-specific message when a prerequisite record is missing instead of passing undefined downstream."],"tags":["typeerror","empty-argument","url","validation"],"backgroundTag":"empty-required-field","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}