{"record":{"id":"e5513cca8ebc47df","repo":"affaan-m/ECC","slug":"canonical-session-snapshot-requires-fieldpath-t-e5513c","errorCode":null,"errorMessage":"Canonical session snapshot requires ${fieldPath} to be a string","messagePattern":"Canonical session snapshot requires (.+?) to be a string","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/session-adapters/canonical-session.js","lineNumber":41,"sourceCode":"  if (typeof context !== 'string' || context.trim().length === 0) {\n    return [];\n  }\n\n  return context\n    .split('\\n')\n    .map(line => line.trim())\n    .filter(Boolean);\n}\n\nfunction ensureString(value, fieldPath) {\n  if (typeof value !== 'string' || value.length === 0) {\n    throw new Error(`Canonical session snapshot requires ${fieldPath} to be a non-empty string`);\n  }\n}\n\nfunction ensureStringAllowEmpty(value, fieldPath) {\n  if (typeof value !== 'string') {\n    throw new Error(`Canonical session snapshot requires ${fieldPath} to be a string`);\n  }\n}\n\nfunction ensureOptionalString(value, fieldPath) {\n  if (value !== null && value !== undefined && typeof value !== 'string') {\n    throw new Error(`Canonical session snapshot requires ${fieldPath} to be a string or null`);\n  }\n}\n\nfunction ensureBoolean(value, fieldPath) {\n  if (typeof value !== 'boolean') {\n    throw new Error(`Canonical session snapshot requires ${fieldPath} to be a boolean`);\n  }\n}\n\nfunction ensureArrayOfStrings(value, fieldPath) {\n  if (!Array.isArray(value) || value.some(item => typeof item !== 'string')) {\n    throw new Error(`Canonical session snapshot requires ${fieldPath} to be an array of strings`);","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/session-adapters/canonical-session.js#L23-L59","documentation":"Thrown by the ensureStringAllowEmpty helper when a field must be a string but is permitted to be empty, yet the value is not a string at all (number, object, etc.). Currently applied to workers[i].intent.objective, which may be an empty objective string but must still be a string.","triggerScenarios":"A worker's intent.objective is set to null, undefined, a number, or an object instead of a string. For example, an adapter assigning objective: worker.task.objective where task.objective is missing and resolves to a non-string.","commonSituations":"An adapter normalizing a session whose task.objective was never set; a downstream transform that converted the objective to a structured object; a test fixture passing a number for the objective.","solutions":["Coerce the objective to a string when building the worker: String(worker.task.objective || '').","Ensure the source session always provides objective as a string (default to '' if absent).","Validate the worker shape with a fixture before persisting."],"exampleFix":"// before\nintent: { objective: worker.task.objective, ... } // task.objective is undefined\n\n// after\nintent: { objective: typeof worker.task.objective === 'string' ? worker.task.objective : '', ... }","handlingStrategy":"validation","validationCode":"// Coerce objective to a string (empty allowed) before building the worker.\nconst objective = typeof raw.objective === 'string' ? raw.objective : '';","typeGuard":"function isStringAllowEmpty(v) { return typeof v === 'string'; }","tryCatchPattern":null,"preventionTips":["Coerce source fields with String(x || '') when building intent.objective.","Keep the objective a flat string, not a structured object."],"tags":["validation","session-schema","canonical-session"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}