Fix inconsistent error handling in RemoveIssueLabelsFn #3

Closed
opened 2025-07-11 15:08:10 -05:00 by b3nw · 0 comments
Owner

Bug: Inconsistent Error Handling Pattern

Issue Description

The RemoveIssueLabelsFn in /operation/label/label.go uses an error accumulation pattern that is inconsistent with the rest of the codebase, which follows a "fail fast" approach.

Current Code (lines 399-415)

var errors []string
for _, labelID := range labelIDs {
    _, err := gitea.Client().DeleteIssueLabel(owner, repo, int64(index), labelID)
    if err != nil {
        errors = append(errors, fmt.Sprintf("failed to remove label %d: %v", labelID, err))
    }
}

if len(errors) > 0 {
    return to.ErrorResult(fmt.Errorf("remove labels from %v/%v/issues/%v errors: %v", owner, repo, int64(index), errors))
}

Problem

  • Continues processing even after encountering errors
  • Inconsistent with other modules that return immediately on first error
  • Could lead to unexpected partial state changes

Expected Behavior

Should follow the "fail fast" pattern used throughout the codebase, returning immediately on the first error encountered.

Affected Functions

  • RemoveIssueLabelsFn (primary issue)
  • Consider reviewing AddIssueLabelsFn and ReplaceIssueLabelsFn for similar patterns

Priority

High - Affects API behavior consistency

# Bug: Inconsistent Error Handling Pattern ## Issue Description The `RemoveIssueLabelsFn` in `/operation/label/label.go` uses an error accumulation pattern that is inconsistent with the rest of the codebase, which follows a "fail fast" approach. ## Current Code (lines 399-415) ```go var errors []string for _, labelID := range labelIDs { _, err := gitea.Client().DeleteIssueLabel(owner, repo, int64(index), labelID) if err != nil { errors = append(errors, fmt.Sprintf("failed to remove label %d: %v", labelID, err)) } } if len(errors) > 0 { return to.ErrorResult(fmt.Errorf("remove labels from %v/%v/issues/%v errors: %v", owner, repo, int64(index), errors)) } ``` ## Problem - Continues processing even after encountering errors - Inconsistent with other modules that return immediately on first error - Could lead to unexpected partial state changes ## Expected Behavior Should follow the "fail fast" pattern used throughout the codebase, returning immediately on the first error encountered. ## Affected Functions - `RemoveIssueLabelsFn` (primary issue) - Consider reviewing `AddIssueLabelsFn` and `ReplaceIssueLabelsFn` for similar patterns ## Priority **High** - Affects API behavior consistency
b3nw added the buglabel-management labels 2025-07-11 15:08:53 -05:00
b3nw closed this issue 2025-07-11 15:27:46 -05:00
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: b3nw/gitea-mcp#3