Skip to content

[Updater] Prefer to use Dependabot::Service directly and as an application error reporter#6846

Merged
brrygrdn merged 10 commits intomainfrom
brrygrdn/extract-updater-error-responsibility
Mar 16, 2023
Merged

[Updater] Prefer to use Dependabot::Service directly and as an application error reporter#6846
brrygrdn merged 10 commits intomainfrom
brrygrdn/extract-updater-error-responsibility

Conversation

@brrygrdn
Copy link
Copy Markdown
Contributor

This is another clear-the-way PR for #6663 [Prototype] Generating grouped update PRs.

Previous PR: #6810

The Dependabot::Updater class implements quite a lot of private methods to assist error handling. As we start to break the updater out into individual strategy classes which handle discrete operations, many of them need to share these methods.

This PR clears the way to start breaking the logic apart primarily via three changes:

  • Stop maintaining a cache of errors inside Dependabot::Updater. This isn't used in any significant way, we can just use Dependabot::Service#errors as a substitute in the one place we need to check if any errors have happened.
  • Prefer to use service. record_update_job_error directly instead of creating an "error_detail" hash to use the Dependabot::Updater#record_error private method, which has been removed
  • Refactor error capturing via Sentry/Raven unto the Dependabot::Service class so it has an explicit receiver that binds it to the backend service and accepts Dependabot objects as arguments

This will allow each individual strategy class to be passed the service so the various record_foo_error helper private methods can be moved without dragging more duplicate private methods in.

Other Changes

There are a few small tidy ups made alongside these changes:

  • Remove an unused error_context method on Dependabot::Updater
  • Remove unused accessors on Dependabot::Service, notably disallow using its Dependabot::ApiClient directly

@brrygrdn brrygrdn requested a review from a team as a code owner March 15, 2023 20:21
Copy link
Copy Markdown
Contributor

@landongrindheim landongrindheim left a comment

Choose a reason for hiding this comment

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

🥇 Again, I'm loving the direction in which you're pushing our components to work together 😍

Comment on lines +55 to +59
extra: extra.merge({
update_job_id: job&.id,
package_manager: job&.package_manager,
dependency_name: dependency&.name
}.compact)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔎 I understand the impulse to send only those key/value pairs for which we have data, but I wonder if the absence of values is valuable for understanding context.

As a 🤏 cheap argument, I'd be able to glean much more insight from:

{
  update_job_id: 1,
  dependency_name: "dependabot-fortran",
  package_manager: nil
}

than

{
  update_job_id: 1,
  dependency_name: "dependabot-fortran"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's fair, I think we should actually expect dependency_name to be passed/present move often -but- I'm err'ing on the side of maintaining existing behaviour for now so I'd prefer to pass on this to avoid test churn for now.

@base_commit_sha = base_commit_sha
# TODO: Collect @created_pull_requests and @errors on the Job object?
@errors = []
# TODO: Collect @created_pull_requests on the Job object?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 👏

Comment on lines -84 to +83
Raven.capture_exception(error, raven_context)
service.capture_exception(error: error, job: job)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📈 This is such a nice improvement!

error = { "error-type": RUN_HALTING_ERRORS.fetch(e.class) }
record_error(error)
service.record_update_job_error(
error_type: RUN_HALTING_ERRORS.fetch(e.class),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔎 I see we weren't handling this before, so no need to change anything. Should we provide a fallback value for Hash#fetch here?

Copy link
Copy Markdown
Contributor Author

@brrygrdn brrygrdn Mar 15, 2023

Choose a reason for hiding this comment

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

I think we probably want it to fail loud as we, ideally, should never enter this method unless we already checked the subject error was present in RUN_HALTING_ERRORS to begin with.

This code might be able to fold up into the call site in another pass? I don't think this is actually reused.

Comment on lines +899 to +902
# This happens if the repo gets removed after a job gets kicked off.
# The service will handle the removal without any prompt from the updater,
# so no need to add an error to the errors array
return if error.is_a? Dependabot::RepoNotFound
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels like the right place for this 👍

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.

2 participants