openai/codex · error · ApplyPatchError

{0}

Error message

{0}

What it means

Display format of the ApplyPatchError::ComputeReplacements variant: applying a patch chunk failed while computing the replacement text for a context window (e.g. the surrounding lines did not match as expected). The interpolated string carries the specific replacement-computation failure reason; this is a patch-content problem, distinct from ParseError and IoError.

Solutions

  1. Regenerate the patch against the current file contents so context lines match
  2. Inspect the ComputeReplacements message to find which chunk failed and hand-fix that region
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/apply-patch/src/lib.rs:105 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/6ed82c36a3940bfd. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/apply-patch/src/lib.rs:105

}

/// Reads the update mode selected for an arg0-dispatched `apply_patch` process.
#[doc(hidden)]
pub fn apply_patch_file_update_mode_from_env() -> ApplyPatchFileUpdateMode {
    match std::env::var(CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR).as_deref() {
        Ok("1") => ApplyPatchFileUpdateMode::PreserveLineEndings,
        _ => ApplyPatchFileUpdateMode::NormalizeToLf,
    }
}

#[derive(Debug, Error, PartialEq)]
pub enum ApplyPatchError {
    #[error(transparent)]
    ParseError(#[from] ParseError),
    #[error(transparent)]
    IoError(#[from] IoError),
    /// Error that occurs while computing replacements when applying patch chunks
    #[error("{0}")]
    ComputeReplacements(String),
    /// A patch path could not be resolved as a path URI.
    #[error(transparent)]
    PathUri(#[from] PathUriParseError),
    /// A raw patch body was provided without an explicit `apply_patch` invocation.
    #[error(
        "patch detected without explicit call to apply_patch. Rerun as [\"apply_patch\", \"<patch>\"]"
    )]
    ImplicitInvocation,
}

impl From<std::io::Error> for ApplyPatchError {
    fn from(err: std::io::Error) -> Self {
        ApplyPatchError::IoError(IoError {
            context: "I/O error".to_string(),
            source: err,
        })
    }

View on GitHub (pinned to 339751715c)