BigPizzaV3/CodexPlusPlus · error · Error

result?.message||'Codex++ 会话读取失败'

Error message

result?.message||'Codex++ 会话读取失败'

What it means

bridge-data.mjs exports the shared graphFromExport used by tests/bridge consumers; its first guard throws Error(result?.message || 'Codex++ 会话读取失败') when result.status is not 'ok'. Same contract as the userscript copy: the caller must pass a successful bridge result.

Solutions

  1. Only call graphFromExport after confirming result?.status==='ok'
  2. Prefer the kind==='canvas-messages' branch for native-shaped results
  3. In tests, pass a stub result with status:'ok', kind:'codex-rollout', content string
  4. Wrap calls in try/catch and surface result.message

Example fix

// before
const g = graphFromExport(result, id);
// after
if (result?.status === 'ok') { const g = graphFromExport(result, id); } else { handleReadFailure(result?.message); }
Defensive patterns

Strategy: validation

Validate before calling

if (result?.status !== 'ok') { handleReadFailure(result?.message); return; }
if (result.kind === 'canvas-messages') { return fromNative(result); }

Type guard

const okRollout = (r) => r?.status==='ok' && r.kind==='codex-rollout' && typeof r.content==='string';

Try / catch

try { const g = graphFromExport(result, id, ann); } catch (e) { console.error('graphFromExport failed:', e.message); }

Prevention

When it happens

Trigger: Calling graphFromExport with a bridge result of {status:'error', message}, or with null/undefined (e.g. a failed readCanvasSource call) — raised through sync.

Common situations: Unit/integration test feeding a simulated error result; a consumer reusing graphFromExport on a raw response without checking status; bridge failing mid-read.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/dc1bb36dc2ea71dd. Report an issue: GitHub.

Appendix: source

Thrown at tools/conversation-canvas/bridge-data.mjs:4

import {parseMessage,buildGraph} from './model.mjs';

export function graphFromExport(result, threadId, annotations={nodes:[]}) {
  if(result?.status!=='ok')throw new Error(result?.message||'Codex++ 会话读取失败');
  if(result.kind!=='codex-rollout'||result.session_id!==threadId||typeof result.content!=='string')throw new Error('会话接口返回了不匹配的数据');
  const messages=[],seen=new Set();
  let declaredId=null;
  // Ignore an unfinished JSONL tail; the next refresh will read the completed line.
  const lines=result.content.slice(0,result.content.lastIndexOf('\n')+1).split('\n');
  for(let i=0;i<lines.length;i++){
    if(!lines[i].trim())continue;
    let r;try{r=JSON.parse(lines[i]);}catch{continue;}
    if(r.type==='session_meta')declaredId=r.payload?.id;
    const m=parseMessage(r,`message-${threadId}-line-${i}`);
    if(m&&!seen.has(m.id)){seen.add(m.id);messages.push(m);}
  }
  if(declaredId&&declaredId!==threadId)throw new Error('记录中的任务 ID 与当前任务不一致');
  return {threadId,title:annotations.title||'当前对话',messages,...buildGraph(messages,annotations)};
}

View on GitHub (pinned to b1ed92e5e4)