Skip to content

Quality: HasCodeowners silently treats permission errors as "file not found"#764

Open
kumburovicbranko682-boop wants to merge 1 commit into
aviator-co:masterfrom
kumburovicbranko682-boop:contribai/improve/quality/hascodeowners-silently-treats-permission
Open

Quality: HasCodeowners silently treats permission errors as "file not found"#764
kumburovicbranko682-boop wants to merge 1 commit into
aviator-co:masterfrom
kumburovicbranko682-boop:contribai/improve/quality/hascodeowners-silently-treats-permission

Conversation

@kumburovicbranko682-boop

Copy link
Copy Markdown

✨ Code Quality

Problem

os.Stat is called and the error is unconditionally discarded. This means permission errors (EACCES), I/O errors (EIO), or other non-NotExist errors are treated identically to the file not existing — returning false. If the .github/CODEOWNERS file exists but the process lacks read permission (e.g., running in a restricted CI container, or after a bad chmod), this function silently returns false, causing downstream logic to skip CODEOWNERS enforcement when it should be enforced.

Severity: medium
File: internal/utils/ghutils/ghutils.go

Solution

Replace the current check with proper error discrimination:

func HasCodeowners(repo *git.Repo) bool {
_, err := os.Stat(filepath.Join(repo.Dir(), ".github/CODEOWNERS"))
if err == nil {
return true
}
if errors.Is(err, fs.ErrNotExist) {
return false
}
// For permission/IO errors, assume the file exists to be safe.
return true
}

Changes

  • internal/utils/ghutils/ghutils.go (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced


🤖 About this PR

This pull request was generated by ContribAI, an AI agent
that helps improve open source projects. The change was:

  1. Discovered by automated code analysis
  2. Generated by AI with context-aware code generation
  3. Self-reviewed by AI quality checks

If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!

Closes #763

…t found"

os.Stat is called and the error is unconditionally discarded. This means permission errors (EACCES), I/O errors (EIO), or other non-NotExist errors are treated identically to the file not existing — returning false. If the .github/CODEOWNERS file exists but the process lacks read permission (e.g., running in a restricted CI container, or after a bad chmod), this function silently returns false, causing downstream logic to skip CODEOWNERS enforcement when it should be enforced.


Affected files: ghutils.go

Signed-off-by: kumburovicbranko682-boop <[email protected]>
@kumburovicbranko682-boop kumburovicbranko682-boop requested a review from a team as a code owner June 27, 2026 12:09
@aviator-app

aviator-app Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app

aviator-app Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

🔃 FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • 🔒 aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • 🔒 internal/utils/ghutils/ghutils.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.

@aviator-app aviator-app Bot requested a review from jainankit June 27, 2026 12:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves error handling in HasCodeowners by explicitly checking for fs.ErrNotExist instead of assuming any error means the file does not exist. The review feedback suggests adding a defensive check to prevent a potential nil pointer dereference if repo is nil, and using separate arguments in filepath.Join for better platform-agnostic path construction.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 12 to +13
func HasCodeowners(repo *git.Repo) bool {
if stat, _ := os.Stat(filepath.Join(repo.Dir(), ".github/CODEOWNERS")); stat != nil {
_, err := os.Stat(filepath.Join(repo.Dir(), ".github/CODEOWNERS"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential nil pointer dereferences, we should add a defensive check to ensure repo is not nil before calling repo.Dir(). Additionally, we can pass the path segments as separate arguments to filepath.Join for better platform-agnostic path construction.

Suggested change
func HasCodeowners(repo *git.Repo) bool {
if stat, _ := os.Stat(filepath.Join(repo.Dir(), ".github/CODEOWNERS")); stat != nil {
_, err := os.Stat(filepath.Join(repo.Dir(), ".github/CODEOWNERS"))
func HasCodeowners(repo *git.Repo) bool {
if repo == nil {
return false
}
_, err := os.Stat(filepath.Join(repo.Dir(), ".github", "CODEOWNERS"))

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.

fix: hascodeowners silently treats permission errors as "file not found"

1 participant