Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCAN-165] Use Err Reporting #3862

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

[SCAN-165] Use Err Reporting #3862

wants to merge 9 commits into from

Conversation

0x1
Copy link
Contributor

@0x1 0x1 commented Jan 31, 2025

Description:

Currently we were not using the error reporting functionality in the GitHub Source. This PR updates that functionality.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@0x1 0x1 requested review from a team as code owners January 31, 2025 15:30
@0x1 0x1 marked this pull request as draft January 31, 2025 15:43
@0x1 0x1 force-pushed the scan-165-use-err-reporting branch from 53e6fba to 3a55b35 Compare January 31, 2025 15:54
@0x1 0x1 marked this pull request as ready for review January 31, 2025 16:13
Copy link
Collaborator

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

Overall this seems like a good approach, just had a few comments.

It looks like the linter is flagging some compilation errors in the test file too.

handleRateLimit func(context.Context, error) bool
handleRateLimit func(context.Context, error, ...errorReporter) bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is errorReporter a vararg to allow for omission at the callsite? Are there places that we don't want to report the rate limit error?

Comment on lines +423 to +425
if err := dedupeReporter.UnitErr(ctx, fmt.Errorf("error caching repo info: %w", err)); err != nil {
ctx.Logger().Error(err, "failed to report unit error")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

An error returned by UnitErr does not mean it failed to record the error. Instead, it's a signal to stop processing and return. That was the intention, anyway, and in practice I think it really would only happen for a context cancellation, which sources should be context-aware anyway.

I'm thinking of removing the error return from those interfaces as it's kind of confusing and not really providing much value.

Comment on lines +462 to +464
// Normalize the URL to the Gist's pull URL.
// See https://github.com/trufflesecurity/trufflehog/pull/2625#issuecomment-2025507937
repo = gist.GetGitPullURL()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this added here? It looks unrelated to error reporting.

Comment on lines +814 to +819
// Only report the error if a reporter was provided
if len(reporter) > 0 {
if err := reporter[0].Err(ctx, fmt.Errorf("exceeded %s rate limit", limitType)); err != nil {
ctx.Logger().Error(err, "failed to report rate limit error")
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to go with the vararg approach, I'd suggest iterating over all the reporters so at least valid calls with multiple reporters aren't silently ignored. It has the added bonus of not having to check the length of the input too.

for _, reporter := range reporters {
    if err := reporter.Err(ctx, ...)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants