Skip to content

Add error type to mark conflicts during apply#166

Merged
bluekeyes merged 3 commits into
masterfrom
bkeyes/conflict-err
Jun 27, 2026
Merged

Add error type to mark conflicts during apply#166
bluekeyes merged 3 commits into
masterfrom
bkeyes/conflict-err

Conversation

@bluekeyes

Copy link
Copy Markdown
Owner

Apply now returns an error with type *Conflict if the error is because of a conflict between the patch and the target. This allows callers to respond to conflicts differently from other errors.

The conflict error message now also includes the file path containing the conflict, which can help understand problems even if the client otherwise doesn't treat conflicts specially.

Detect any conflict

if errors.Is(err, &patch2pr.Conflict{}) {
  // respond to conflict
}

if conflict, ok := errors.AsType[*patch2pr.Conflict](err); ok {
  switch conflict.Type {
    // respond to different conflicts differently
  }
}

Detect specific conflict

if errors.Is(err, &patch2pr.Conflict{Type: patch2pr.ConflictModifiedFileMissing}) {
  // respond to conflict
}

Alternative approach to #165.

Apply now returns an error with type *Conflict if the error is because
of a conflict between the patch and the target. This allows callers to
respond to conflicts differently from other errors.
@bluekeyes bluekeyes merged commit c7d8914 into master Jun 27, 2026
1 check passed
@bluekeyes bluekeyes deleted the bkeyes/conflict-err branch June 27, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant