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

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

Closed
djfpaagman opened this issue Dec 3, 2024 · 1 comment · Fixed by #105

Comments

@djfpaagman
Copy link
Contributor

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

# Programs enqueuing multiple jobs with different parameters but the
# same idempotency key is a bug.
if record.raw_arguments != serialized_job["arguments"]
raise ArgumentMismatchError.new(serialized_job["arguments"], record.raw_arguments)
end

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
Copy link
Owner

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

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 a pull request may close this issue.

2 participants