fractaledmind / acidic_job

Elegant, resilient, durable workflows for Rails apps
https://fractaledmind.github.io/acidic_job/
MIT License
493 stars 10 forks source link

Error classes themself raise ArgumentError "wrong number of arguments (given 2, expected 0..1)" #104

Closed djfpaagman closed 17 hours ago

djfpaagman commented 18 hours ago

I ran into this branch of the code because of some shenigans:

https://github.com/fractaledmind/acidic_job/blob/6f2b356b35da27a32d4cae8ece46b3de75308bdd/lib/acidic_job/workflow.rb#L47-L51

This code itself fails though:

ArgumentError: wrong number of arguments (given 2, expected 0..1) (ArgumentError)

acidic_job (1.0.0.rc1) lib/acidic_job/errors.rb in initialize at line 33 acidic_job (1.0.0.rc1) lib/acidic_job/workflow.rb in new at line 50 acidic_job (1.0.0.rc1) lib/acidic_job/workflow.rb in block (2 levels) in execute_workflow at line 50 activerecord (8.0.0) lib/active_record/connection_adapters/abstract/transaction.rb in block in within_new_transaction at line 626 activesupport (8.0.0) lib/active_support/concurrency/null_lock.rb in synchronize at line 9 activerecord (8.0.0) lib/active_record/connection_adapters/abstract/transaction.rb in within_new_transaction at line 623 activerecord (8.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb in within_new_transaction at line 367 activerecord (8.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb in transaction at line 359 activerecord (8.0.0) lib/active_record/transactions.rb in block in transaction at line 234 activerecord (8.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb in with_connection at line 406 activerecord (8.0.0) lib/active_record/connection_handling.rb in with_connection at line 310 activerecord (8.0.0) lib/active_record/transactions.rb in transaction at line 233 acidic_job (1.0.0.rc1) lib/acidic_job/workflow.rb in block in execute_workflow at line 43 activesupport (8.0.0) lib/active_support/notifications.rb in block in instrument at line 210 activesupport (8.0.0) lib/active_support/notifications/instrumenter.rb in instrument at line 58 activesupport (8.0.0) lib/active_support/notifications.rb in instrument at line 210 acidic_job (1.0.0.rc1) lib/acidic_job.rb in instrument at line 24 acidic_job (1.0.0.rc1) lib/acidic_job/workflow.rb in execute_workflow at line 33

I think it's because of the super call in the initializer, depending on the number of arguments you get different errors from different initializers, but this isn't super clear from the call stack:

> tour-brain(dev)> AcidicJob::ArgumentMismatchError.new
(tour-brain):19:in `new': wrong number of arguments (given 0, expected 2) (ArgumentError)
        from (tour-brain):19:in `<main>'

tour-brain(dev)> AcidicJob::ArgumentMismatchError.new("test")
(tour-brain):20:in `new': wrong number of arguments (given 1, expected 2) (ArgumentError)
        from (tour-brain):20:in `<main>'

tour-brain(dev)> AcidicJob::ArgumentMismatchError.new("test", "test")
(tour-brain):21:in `new': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
        from (tour-brain):21:in `<main>'

But:

> tour-brain(dev)> AcidicJob::Error.new("test", "test")
(tour-brain):23:in `initialize': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
tour-brain(dev)> AcidicJob::Error.new("test")
=> #<AcidicJob::Error: test>
fractaledmind commented 17 hours ago

This is a great find @djfpaagman! Thank you for such a clear report. I have just opened PR #105 to resolve this issue.