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

Ensure task_context is never nil when error_handler is called #1059

Merged

Conversation

yjukaku
Copy link
Contributor

@yjukaku yjukaku commented Jul 29, 2024

If @run.persist_error(error) raises an error, task_context is never assigned and then is nil when MaintenanceTasks.error_handler is called.

@@ -182,7 +182,7 @@ def on_error(error)
end
errored_element = @errored_element if defined?(@errored_element)
ensure
MaintenanceTasks.error_handler.call(error, task_context, errored_element)
MaintenanceTasks.error_handler.call(error, task_context || {}, errored_element)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about assigning task_context = {} at the start of this method instead? That would let us drop the else branch above as well.

def on_error(error)
  task_context = {}

  @ticker.persist if defined?(@ticker)

  if defined?(@run)
    ...
    task_context = { ... }
  end
  ...
ensure
  MaintenanceTasks.error_handler.call(error, task_context, errored_element)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, that makes it much cleaner 👍

Copy link
Contributor

@adrianna-chang-shopify adrianna-chang-shopify left a comment

Choose a reason for hiding this comment

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

Can you squash your commits please @yjukaku and I'll merge ?

@yjukaku yjukaku force-pushed the yjukaku-fix-nil-task-context branch from a2c0137 to fdc52ad Compare August 28, 2024 16:17
@yjukaku
Copy link
Contributor Author

yjukaku commented Aug 28, 2024

@adrianna-chang-shopify Done!

@adrianna-chang-shopify adrianna-chang-shopify merged commit ece9bb5 into Shopify:main Aug 29, 2024
21 checks passed
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