{"record":{"id":"acfcecb1ecdcceb2","repo":"can1357/oh-my-pi","slug":"apply-failed-message","errorCode":null,"errorMessage":"Apply failed: ${message}","messagePattern":"Apply failed: (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/resolve.ts","lineNumber":262,"sourceCode":"\tconst baseDetails: ResolveDetails = {\n\t\taction: params.action,\n\t\treason: params.reason,\n\t\tsourceToolName: options.sourceToolName,\n\t\tlabel: options.label,\n\t};\n\tif (params.action === \"apply\") {\n\t\tlet result: AgentToolResult<unknown>;\n\t\ttry {\n\t\t\tresult = await options.apply(params.reason);\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\toptions.onApplyError?.(error);\n\t\t\t} catch {\n\t\t\t\t// Requeue hook must not mask the original apply failure.\n\t\t\t}\n\t\t\tif (error instanceof ToolError) throw error;\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new ToolError(`Apply failed: ${message}`);\n\t\t}\n\t\treturn {\n\t\t\t...result,\n\t\t\tdetails: {\n\t\t\t\t...baseDetails,\n\t\t\t\t...(result.details != null ? { sourceResultDetails: result.details } : {}),\n\t\t\t},\n\t\t};\n\t}\n\tif (options.reject != null) {\n\t\tconst result = await options.reject(params.reason);\n\t\tif (result != null) {\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\tdetails: {\n\t\t\t\t\t...baseDetails,\n\t\t\t\t\t...(result.details != null ? { sourceResultDetails: result.details } : {}),\n\t\t\t\t},","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/resolve.ts#L244-L280","documentation":"runResolveInvocation applies a staged resolution (approve/apply of a pending action). When the underlying apply throws a non-ToolError exception, it rethrows as ToolError('Apply failed: <message>') so the tool layer surfaces a consistent error. The optional onApplyError/requeue hook is invoked first but its own failure is swallowed.","triggerScenarios":"The apply path (patch application, file write, hook execution) throws a generic Error — e.g. patch context mismatch, filesystem permission denied, or an internal exception that is not a ToolError.","commonSituations":"Staged edit no longer matches the file (file changed since preview); read-only working tree; disk full; a plugin/hook corrupted state.","solutions":["Read the embedded message after 'Apply failed: ' to find the root cause","Re-check the target files for changes and re-run the plan/preview to stage a fresh action","Fix filesystem permissions or free disk space if the message indicates EACCES/ENOSPC","Retry the resolve once the underlying cause is fixed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before applying, confirm the staged target still matches\ncurrent = await Bun.file(targetPath).text();\nif (current !== previewedContent) throw new Error(\"File changed since preview; re-stage\");","typeGuard":null,"tryCatchPattern":"try { await resolveApply(); } catch (e) { if (e instanceof ToolError && e.message.startsWith(\"Apply failed:\")) { logger.warn(\"resolve apply failed\", { cause: e.message.slice(\"Apply failed: \".length) }); /* re-stage and retry */ } else throw e; }","preventionTips":["Don't modify files between staging the preview and applying","Re-run the preview/plan if the working tree changed","Check file permissions and disk space before applying large edits"],"tags":["apply","patch","tool-error"],"backgroundTag":"patch-apply-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}