yegor256/0pdd

`GitlabRepo#issue` and `close_issue` rescue only `NotFound`; `Unauthorized`/`Forbidden`/`TooManyRequests` propagate unhandled, plus typo `"can' comment"`

Open

#853 建立於 2026年5月11日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Ruby (37 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (142 star)
PR 合併指標
 (PR 指標待抓取)

描述

What happens

In objects/vcs/gitlab.rb, the GitLab VCS adapter rescues only Gitlab::Error::NotFound:

def issue(issue_id)
  ...
rescue Gitlab::Error::NotFound => e
  raise "The issue most probably is not found, can' comment: #{e.message}"
end

def close_issue(issue_id)
  @client.close_issue(@repo.name, issue_id)
rescue Gitlab::Error::NotFound => e
  raise "The issue most probably is not found, can't close: #{e.message}"
end

def add_comment(issue_id, comment)
  @client.create_issue_note(@repo.name, issue_id, comment)
rescue Gitlab::Error::NotFound => e
  raise "The issue most probably is not found, can't comment: #{e.message}"
end

Three issues here.

  1. Gitlab::Error::Unauthorized, Gitlab::Error::Forbidden, Gitlab::Error::TooManyRequests, and Net::OpenTimeout/Errno::ECONNREFUSED (network failures) are not caught. A revoked GitLab token, a rate limit, or a transient network error therefore crashes the call with the raw upstream exception class, defeating the wrapper's purpose of producing a stable error contract.

  2. The wrapper is also inconsistent with the same file's exists? method (lines 120-133), which does rescue both Gitlab::Error::NotFound and Gitlab::Error::Forbidden. So the policy is "narrow rescue here, wider rescue there" within one class.

  3. There is a typo on line 38: "The issue most probably is not found, can' comment" — a missing letter (and a missing apostrophe pairing) compared to "can't close" and "can't comment" elsewhere in the same file.

This is the same defect family as the recently-accepted zerocracy/judges-action#1357#1362 (too-narrow Octokit rescues) and as the GithubRepo neighbour of this same gitlab.rb (already tracked there via @todo #312).

What should happen

Widen each rescue to the full family of Gitlab::Error plus common network errors, matching the wider rescue convention already used by exists?:

rescue Gitlab::Error::NotFound,
       Gitlab::Error::Unauthorized,
       Gitlab::Error::Forbidden,
       Gitlab::Error::TooManyRequests => e
  raise "Can't reach GitLab issue #{issue_id}: #{e.message}"
end

And fix the typo "can' comment""can't comment" on line 38.

Result: revoked tokens, rate limits, and missing issues all surface as the same wrapper exception type the rest of 0pdd already handles, the wrapper's stable-error contract is honoured, and the typo no longer appears in operator-facing logs.

貢獻者指南