{"record":{"id":"160410afaeefe976","repo":"affaan-m/ECC","slug":"unsupported-opencode-session-target-target","errorCode":null,"errorMessage":"Unsupported OpenCode session target: ${target}","messagePattern":"Unsupported OpenCode session target: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/session-adapters/opencode.js","lineNumber":154,"sourceCode":"    const absoluteExplicit = path.resolve(cwd, explicitTarget);\n    if (fs.existsSync(absoluteExplicit) && isSessionInfoFile(absoluteExplicit)) {\n      return { sessionInfoPath: absoluteExplicit, sourceTarget: { type: 'opencode-session-file', value: absoluteExplicit } };\n    }\n\n    const byId = findSessionInfoById(storageDir, explicitTarget);\n    if (byId) {\n      return { sessionInfoPath: byId, sourceTarget: { type: 'opencode', value: explicitTarget } };\n    }\n\n    throw new Error(`OpenCode session not found: ${explicitTarget}`);\n  }\n\n  if (isOpencodeSessionFileTarget(target, cwd)) {\n    const absoluteTarget = path.resolve(cwd, target);\n    return { sessionInfoPath: absoluteTarget, sourceTarget: { type: 'opencode-session-file', value: absoluteTarget } };\n  }\n\n  throw new Error(`Unsupported OpenCode session target: ${target}`);\n}\n\nfunction readMessageFiles(messageDir) {\n  if (!fs.existsSync(messageDir) || !fs.statSync(messageDir).isDirectory()) {\n    return [];\n  }\n\n  try {\n    return fs.readdirSync(messageDir)\n      .filter(name => name.startsWith('msg_') && name.endsWith('.json'))\n      .map(name => path.join(messageDir, name));\n  } catch {\n    return [];\n  }\n}\n\nfunction deriveModelFromMessages(messageFiles) {\n  for (const filePath of messageFiles.slice(0, MAX_MESSAGE_SCAN)) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/session-adapters/opencode.js#L136-L172","documentation":"Terminal guard of resolveSessionInfoPath: the target string is neither 'latest', a resolvable session id, nor a recognized OpenCode session file path, so the adapter rejects it. This is the OpenCode unsupported-target error.","triggerScenarios":"resolveSessionInfoPath called with '', a directory path, a Claude/Codex session path, or any value isOpencodeSessionFileTarget(target, cwd) rejects, with explicitTarget null or unresolvable.","commonSituations":"Routing a session file from another harness to the OpenCode adapter; empty config value from an unset env var; passing a directory instead of a session file; relative path resolved from an unexpected cwd.","solutions":["Use 'latest', a valid session id, or an existing OpenCode session file path.","Confirm the path points to a session info file (not a directory or message file).","Trim and log the target value to catch empty/misquoted input.","Dispatch to the correct adapter for Claude/Codex targets.","Verify cwd for relative paths."],"exampleFix":"// before\nresolve(targetFromEnv); // may be '' -> throws\n// after\nconst t = (targetFromEnv || '').trim();\nif (!t || (t !== 'latest' && !fs.existsSync(t))) {\n  throw new Error(`OPENCODE_TARGET='${targetFromEnv}' is not 'latest', a session id, or an existing session file`);\n}\nresolve(t);","handlingStrategy":"validation","validationCode":"if (typeof target !== 'string' || !target.trim()) throw new Error('OpenCode target must be a non-empty string');\nif (target !== 'latest' && !fs.existsSync(target)) throw new Error(`OpenCode target '${target}' not 'latest' or an existing file`);","typeGuard":"function isValidOpencodeTarget(t) { return t === 'latest' || (typeof t === 'string' && t.trim().length > 0); }","tryCatchPattern":"try { return adapter.resolveSessionInfoPath(target); } catch (e) { if (/^Unsupported OpenCode session target:/.test(e.message)) console.error(`Valid forms: 'latest', session id, session file path; got '${target}'`); throw e; }","preventionTips":["Validate the three accepted target forms upstream","Guard against unset env vars yielding empty strings","Dispatch Claude/Codex targets to their own adapters","Log raw values to catch quoting issues"],"tags":["session","opencode","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}