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

Log installments errors by default #235

Merged
merged 2 commits into from
Jul 20, 2021

Conversation

kennyadsl
Copy link
Member

At the moment, by default, all installment processing errors are swallowed and there's no way for a developer to understand what's happening. Of course, they can create a custom handler with the processing_error_handler configuration provided but usually, when the first errors happen, it's too late and those errors are lost.

We are not raising errors of this job because if there's a retry mechanism in place for Active Job, the installment will be reprocessed twice. Once by Active Job and once by the installment retry mechanism already provided by the extension.

Logging to Rails.error is a middle-ground that allows to intercept the message of the exception. Still, creating a custom handler based on the bug tracker/exception handler used is the suggested option here.

This PR also changes the signature of the handler call method (or proc) to allow passing the installment along with the exception.

@kennyadsl kennyadsl self-assigned this Jul 12, 2021
@kennyadsl kennyadsl force-pushed the kennyadsl/log-installments-errors-by-default branch from c2324d2 to 40905bd Compare July 12, 2021 15:41
@kennyadsl
Copy link
Member Author

🔴 Linting failures are not related to this PR.

error_handler = SolidusSubscriptions.configuration.processing_error_handler

if error_handler
proc_or_method = error_handler.is_a?(Proc) ? error_handler : error_handler.method(:call)
Copy link
Contributor

@cesartalves cesartalves Jul 12, 2021

Choose a reason for hiding this comment

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

Are we adding this arity check for compatibility with older versions? What's the purpose here?

I feel that this adds a bit of extra complexity (specially when comparing an arity of -2), and handling some logic which should not be the responsibility of this job.

Some users might also override the default class with one which requires both the installment and the error, in which case the arity would be 2 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you are right. I thought that an existing proc that only had one argument (like proc { |e| raise e }) wouldn't work but it seems that it handles not having the second argument without breaking. I'll remove the extra code, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, IIR my meta-programming correctly, Procs do not arity check, whilst lambdas do 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, so we need to hope that people didn't use a lambda for their handler?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. But users who're upgrading should be able to deal with this right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but if they didn't notice the change they'll end up with an exception in production, not ideal.

@kennyadsl kennyadsl force-pushed the kennyadsl/log-installments-errors-by-default branch from 40905bd to ca3dcaf Compare July 13, 2021 09:27
Copy link
Contributor

@cesartalves cesartalves left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for this addition 💯

At the moment, by default, all installment prceissing errors are
swallowed and there's no way for a developer to understand what's
happening. Of course they can create a custom handler with the
processing_error_handler configuration provided but usually, when
the first errors happen, it's too late and those errors are lost.

We are not raising errors of this job because if there's a retry
mechanism in place for Active Job, the installment will be
reprocessed twice. Once by Active Job and once by the installment
retry mechanism already provided by the extension.

Logging to Rails.error is a middle-ground that allows to intercept
the message of the exception. Still, creating a custom handler
based on the bug tracker/exception handler used is the suggested
option here.
This way we can provide more flexibility on things that can be
done when an error occurs.

In the provided RailsLogger handler, we'll also print the ID
of the installment.
@kennyadsl kennyadsl force-pushed the kennyadsl/log-installments-errors-by-default branch from ca3dcaf to 0317e22 Compare July 13, 2021 14:23
@kennyadsl kennyadsl merged commit c6c9fea into master Jul 20, 2021
@kennyadsl kennyadsl deleted the kennyadsl/log-installments-errors-by-default branch July 20, 2021 14:30
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