{"record":{"id":"ee99d411c2aff04d","repo":"hcengineering/platform","slug":"namespace-not-specified","errorCode":null,"errorMessage":"Namespace not specified","messagePattern":"Namespace not specified","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kvs-client/src/client.ts","lineNumber":50,"sourceCode":"\n  return new KeyValueClientImpl(namespace, baseUrl, token, retryTimeoutMs)\n}\n\nclass KeyValueClientImpl implements KeyValueClient {\n  private readonly requestInit: RequestInit\n\n  constructor (\n    private readonly namespace: string,\n    private readonly baseUrl: string,\n    private readonly token?: string,\n    private readonly retryTimeoutMs: number = 5000\n  ) {\n    if (baseUrl === '') {\n      throw new Error('Key-value API URL not specified')\n    }\n\n    if (namespace === '' || namespace === undefined) {\n      throw new Error('Namespace not specified')\n    }\n\n    const isBrowser = typeof window !== 'undefined'\n\n    this.requestInit = {\n      keepalive: true,\n      headers: {\n        ...(this.token === undefined\n          ? {}\n          : {\n              Authorization: 'Bearer ' + this.token\n            })\n      },\n      ...(isBrowser ? { credentials: 'include' } : {})\n    }\n  }\n\n  async setValue<T>(key: string, value: T): Promise<void> {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/kvs-client/src/client.ts#L32-L68","documentation":"The KvsClient constructor throws this Error when the namespace parameter is an empty string or undefined. Every key-value operation is scoped to a namespace, so the client refuses to initialize without one. Fail-fast behavior surfaces configuration mistakes immediately instead of producing requests to the wrong or nonexistent namespace.","triggerScenarios":"`new KvsClient('', baseUrl)` or `new KvsClient(undefined as any, baseUrl)` — an empty/undefined namespace passed to the constructor.","commonSituations":"Namespace sourced from an unset environment variable or optional config field, copy-pasted client setup where the namespace argument was left blank, or a refactor that renamed the config key feeding the namespace.","solutions":["Pass a concrete non-empty namespace string as the first constructor argument, e.g. `new KvsClient('my-app', baseUrl)`.","Verify the source of the namespace (env var/config) actually contains a value at startup.","Validate the namespace before constructing: `if (!ns) throw new Error('namespace required')`."],"exampleFix":"// before\nconst client = new KvsClient(config.namespace ?? '', baseUrl)\n// after\nif (!config.namespace) throw new Error('KVS namespace is required')\nconst client = new KvsClient(config.namespace, baseUrl)","handlingStrategy":"validation","validationCode":"function assertNamespace(ns: string | undefined): asserts ns is string {\n  if (typeof ns !== 'string' || ns === '') throw new Error('KVS namespace must be a non-empty string')\n}\nassertNamespace(config.namespace)\nconst client = new KvsClient(config.namespace, baseUrl)","typeGuard":"function isValidNamespace(ns: unknown): ns is string {\n  return typeof ns === 'string' && ns.length > 0\n}","tryCatchPattern":"try {\n  const client = new KvsClient(ns, url)\n} catch (e) {\n  if ((e as Error).message === 'Namespace not specified') {\n    throw new Error('Configuration error: KVS namespace missing — check config/env')\n  }\n  throw e\n}","preventionTips":["Define namespaces as constants rather than loose config strings.","Validate namespace presence at startup alongside other required config.","Avoid optional chaining chains like `config.a?.b?.ns` that can silently yield undefined."],"tags":["configuration","constructor","kvs","namespace"],"backgroundTag":"missing-namespace","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}