Fix Ruby 3.2+ compatibility in aws-sdk-neptunedata detailed_message overrides#3381
Conversation
In Ruby 3.2, Exception#full_message was updated to internally call detailed_message(highlight:) with a keyword argument. All 34 error classes in aws-sdk-neptunedata override detailed_message to expose the API-level field, but none of them accepted the highlight: keyword, causing ArgumentError when Ruby or any tooling (e.g. OpenTelemetry SDK's span.record_exception) calls full_message on these exceptions. The fix adds `highlight: true, **` to each override, making them compatible with Ruby 3.2+ while remaining fully backward compatible with earlier Ruby versions where full_message does not call detailed_message with keyword arguments. Fixes: ArgumentError: wrong number of arguments (given 1, expected 0)
Ruby 3.2 updated Exception#full_message to call detailed_message(highlight:) with a keyword argument. The errors_module.mustache template generates detailed_message overrides for error members, but the generated signature did not accept the highlight: keyword, causing ArgumentError. Update error_list.rb to expose a detailed_message flag on members named detailed_message, and update the template to generate: def detailed_message(highlight: true, **) for those members, maintaining backward compatibility with Ruby < 3.2. The generated aws-sdk-neptunedata/errors.rb was already updated in the previous commit.
The RBS generator was producing `() -> ::String` for the detailed_message member, but after the Ruby 3.2+ fix the method signature is now `def detailed_message(highlight: true, **)`. Update the RBS generator to emit `(?highlight: bool) -> ::String` for members named detailed_message, consistent with the generated sig/errors.rbs.
|
Hey, thanks for the PR! This is a tricky case where we have a name collision between an API member name and a Ruby built-in method. The fix as proposed will still always return the API member value; meaning when Ruby's We are currently looking into a few different solutions and will circle back with a resolution. |
NP, thanks for the feedback. Actually this PR should be a draft since I still have no good solution, and realized (as you said) doing those changes will not solve the issue properly but just silence a not ideal behavior (at least would not break the code). I'm patching it in my application since it's braking there. |
|
Yes please to closing the pr and creating an issue. That would be great. I will post updates in the issue once we come to a resolution. |
Summary
In Ruby 3.2,
Exception#full_messagewas updated to internally calldetailed_message(highlight:)passing a keyword argument (source). All 34 error classes inaws-sdk-neptunedataoverridedetailed_messageto expose the API-leveldetailed_messagefield, but none accepted thehighlight:keyword — causing anArgumentErrorwhenever Ruby or tooling callsfull_messageon these exceptions.A common trigger is OpenTelemetry SDK's
span.record_exception(e)(code here), which callse.full_message(highlight: false, order: :top)(code here) to capture the stacktrace. This silently breaks tracing and any instrumentation that records exceptions on spans.Change
Added
highlight: true, **to all 34detailed_messageoverrides inerrors.rband updated the corresponding.rbstype signatures.Backward Compatibility
Fully backward compatible. Keyword arguments with defaults are valid Ruby syntax since 2.0. In Ruby < 3.2,
full_messagenever callsdetailed_messagewith keyword arguments, so the added parameter is never passed — no behavior change.Note on Code Generation
errors.rbandsig/errors.rbsare generated files. The corresponding generator template will also need to be updated to preserve this fix on future regeneration.