{"record":{"id":"22874c8b975d241a","repo":"affaan-m/ECC","slug":"structured-session-targets-require-a-non-empty-str","errorCode":null,"errorMessage":"Structured session targets require a non-empty string value","messagePattern":"Structured session targets require a non-empty string value","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/session-adapters/registry.js","lineNumber":46,"sourceCode":"    ...sharedOptions,\n    ...(options.adapterOptions && options.adapterOptions[adapterId]\n      ? options.adapterOptions[adapterId]\n      : {})\n  };\n}\n\nfunction createDefaultAdapters(options = {}) {\n  return [\n    createClaudeHistoryAdapter(buildDefaultAdapterOptions(options, 'claude-history')),\n    createDmuxTmuxAdapter(buildDefaultAdapterOptions(options, 'dmux-tmux')),\n    createCodexWorktreeAdapter(buildDefaultAdapterOptions(options, 'codex-worktree')),\n    createOpencodeAdapter(buildDefaultAdapterOptions(options, 'opencode'))\n  ];\n}\n\nfunction coerceTargetValue(value) {\n  if (typeof value !== 'string' || value.trim().length === 0) {\n    throw new Error('Structured session targets require a non-empty string value');\n  }\n\n  return value.trim();\n}\n\nfunction normalizeStructuredTarget(target, context = {}) {\n  if (!target || typeof target !== 'object' || Array.isArray(target)) {\n    return {\n      target,\n      context: { ...context }\n    };\n  }\n\n  const value = coerceTargetValue(target.value);\n  const type = typeof target.type === 'string' ? target.type.trim() : '';\n  if (type.length === 0) {\n    throw new Error('Structured session targets require a non-empty type');\n  }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/session-adapters/registry.js#L28-L64","documentation":"coerceTargetValue in the session adapter registry validates that a structured session target's value is a non-empty string; it throws this when value is not a string, an empty string, or whitespace-only. Structured targets (e.g. { type, value }) must carry a usable string value for the adapter to resolve.","triggerScenarios":"Passing a structured target like { type: 'claude-history', value: null } / { value: '' } / { value: 42 } / { value: '   ' } into normalizeStructuredTarget/registry resolution, typically from programmatic callers or JSON config with missing/blank fields.","commonSituations":"Config files where the target value was left blank; env var unset then interpolated to empty string; JSON deserialization yielding null instead of string; callers passing a numeric id instead of a string.","solutions":["Always pass a non-empty string value: String(value) with a trim and length check before building the target.","Fix the config/env source so the value is populated (e.g. default to 'latest').","Coerce numeric ids to strings explicitly (String(id)).","Validate structured targets with a schema (zod/ajv) at the boundary before calling the registry."],"exampleFix":"// before\nregistry.normalize({ type: 'claude-history', value: process.env.SESSION }); // SESSION unset -> ''\n// after\nconst value = (process.env.SESSION ?? 'latest').trim();\nif (!value) throw new Error('SESSION must be a non-empty string');\nregistry.normalize({ type: 'claude-history', value });","handlingStrategy":"type-guard","validationCode":"function assertStructuredTarget(t) {\n  if (!t || typeof t !== 'object') throw new Error('Structured target must be an object');\n  if (typeof t.value !== 'string' || t.value.trim().length === 0) throw new Error('Structured target.value must be a non-empty string');\n}","typeGuard":"function hasNonEmptyStringValue(t) { return typeof t === 'object' && t !== null && typeof t.value === 'string' && t.value.trim().length > 0; }","tryCatchPattern":"try { return registry.normalizeStructuredTarget(target); } catch (e) { if (e.message === 'Structured session targets require a non-empty string value') throw new Error(`Bad target.value=${JSON.stringify(target?.value)}; provide a non-empty string`); throw e; }","preventionTips":["Validate structured targets with a schema at boundaries","Default blank values to 'latest' where appropriate","Coerce numeric/uuid ids with String() before building targets","Fail fast on empty env/config interpolation"],"tags":["validation","session","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}