{"record":{"id":"299c83472d92f36a","repo":"can1357/oh-my-pi","slug":"result-must-be-an-object-containing-either-data-or","errorCode":null,"errorMessage":"result must be an object containing either data or error. ${YIELD_RESULT_FORMAT_HINT}","messagePattern":"result must be an object containing either data or error\\. (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/yield.ts","lineNumber":370,"sourceCode":"\t\tthis.#rejectUnknownSections = rejectUnknownSections;\n\t\tthis.#knownSectionLabels = knownSectionLabels;\n\t\tthis.#isKnownSection = isKnownSection;\n\t\tthis.description = prompt.render(yieldDescription, { hasOutputSchema: validate !== undefined });\n\t\tthis.parameters = parameters;\n\t}\n\n\tasync execute(\n\t\t_toolCallId: string,\n\t\tparams: unknown,\n\t\t_signal?: AbortSignal,\n\t\t_onUpdate?: AgentToolUpdateCallback<YieldDetails>,\n\t\t_context?: AgentToolContext,\n\t): Promise<AgentToolResult<YieldDetails>> {\n\t\tconst raw = params as Record<string, unknown>;\n\t\tconst yieldType = parseYieldType(raw.type);\n\t\tconst resultRecord = resolveResultRecord(raw, yieldType);\n\t\tif (resultRecord === undefined) {\n\t\t\tthrow new Error(`result must be an object containing either data or error. ${YIELD_RESULT_FORMAT_HINT}`);\n\t\t}\n\t\tconst errorMessage = typeof resultRecord.error === \"string\" ? resultRecord.error : undefined;\n\t\tlet data = resultRecord.data;\n\t\tconst useLastTurn =\n\t\t\terrorMessage === undefined && data === undefined && yieldType !== undefined && !(\"error\" in resultRecord);\n\t\t// Incremental array-typed sections carry partial data (one finding, one\n\t\t// field) that cannot satisfy the full output schema; the assembled result\n\t\t// is validated as a whole at finalization (executor finalizeSubprocessOutput).\n\t\tconst isIncremental = Array.isArray(yieldType) && yieldType.length > 0;\n\n\t\tif (errorMessage !== undefined && data !== undefined) {\n\t\t\tthrow new Error(\"result cannot contain both data and error\");\n\t\t}\n\t\tif (errorMessage === undefined && data === undefined && yieldType === undefined) {\n\t\t\tthis.#emptyResultFailures++;\n\t\t\tif (this.#emptyResultFailures > MAX_EMPTY_RESULT_RETRIES) {\n\t\t\t\tconst attemptCount = this.#emptyResultFailures;\n\t\t\t\tthis.#emptyResultFailures = 0;","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/yield.ts#L352-L388","documentation":"YieldTool.execute requires the top-level `result` parameter to be an object containing at least one of `data` or `error`. resolveResultRecord returns undefined when `result` is missing, not an object, or has neither key, and execute throws this Error with YIELD_RESULT_FORMAT_HINT: submit success as {\"result\":{\"data\":<output>}} or failure as {\"result\":{\"error\":\"message\"}}.","triggerScenarios":"Calling yield with `result` absent, `result` set to a non-object (string/number/array), or `result: {}` containing neither `data` nor `error` (and no usable `type`-based last-turn fallback).","commonSituations":"A model emits the payload at the top level instead of nesting under `result.data`; it puts data directly in `result` (`result: \"text\"`); it includes extra keys but forgets both `data` and `error`.","solutions":["Wrap the payload as {\"result\":{\"data\": <your output>}} for success.","Report failure as {\"result\":{\"error\": \"message\"}}.","Ensure `result` is a JSON object, not a scalar or array.","If intentionally deferring to last-turn output, keep `type` set and omit both `data` and `error` per the useLastTurn path — otherwise include one of them."],"exampleFix":"// before\nyield({ result: \"the answer\", status: \"success\" })\n// after\nyield({ result: { data: \"the answer\" } })","handlingStrategy":"type-guard","validationCode":"const r = params.result; if (typeof r !== \"object\" || r === null || Array.isArray(r) || !(\"data\" in r) && !(\"error\" in r)) throw new Error('result must be {data:...} or {error:...}');","typeGuard":"function hasResultRecord(p: unknown): p is { result: { data?: unknown; error?: string } } { const r = (p as { result?: unknown })?.result; return typeof r === \"object\" && r !== null && !Array.isArray(r) && (\"data\" in r || \"error\" in r); }","tryCatchPattern":"try { await yield(params); } catch (e) { if (String(e.message).includes(\"result must be an object containing either data or error\")) { return yield({ result: { data: params.result ?? params } }); } throw e; }","preventionTips":["Always nest payloads under result.data (or result.error for failures).","Never pass scalars/arrays as `result`.","Add result-shape validation to prompt/tool schema so models emit the right shape.","Remember the last-turn fallback only applies when `type` is set and neither key is present."],"tags":["yield","validation","tool-parameters"],"backgroundTag":"missing-result-payload","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}