Bug #22407
closedRuby 3.1+ can munge error messages returned by RailsAPI
Description
I haven't tracked down all the factors at play here, but I am seeing this sdk/go/arvadosclient
test failure on a fresh development install on Debian 12:
---------------------------------------------------------------------- FAIL: arvadosclient_test.go:119: ServerRequiredSuite.TestErrorResponse arvadosclient_test.go:128: c.Assert(err, ErrorMatches, "arvados API server error: .*") ... error string = "" + ... "arvados API server error: #<ActiveModel::UnknownAttributeError: unknown attribute 'bogus_attr' for Log.\n" + ... "\n" + ... " raise UnknownAttributeError.new(self, k.to_s)\n" + ... " ^^^^^> (req-c60vk3fbnufo32wo3bv5) (422: 422 Unprocessable Entity) returned by 0.0.0.0:44737" ... regex string = "arvados API server error: .*"
This passes on my regular box. The difference is that there, the error string is only:
... error string = "arvados API server error: #<ActiveModel::UnknownAttributeError: unknown attribute 'bogus_attr' for Log.> (req-1onsacd6a20qs4qf5vc5) (422: 422 Unprocessable Entity) returned by 0.0.0.0:50171"
With the newlines introduced by the backtrace-ish line, .*
fails to match the rest of the string.
I assume we don't want these lines to ever appear. Given that, it would be good to track down where they're coming from and make sure they're disabled in a reliable way.
For reference:
$ ruby -v ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]
Updated by Brett Smith about 1 month ago
- Target version set to Development 2025-01-08
- Assigned To set to Brett Smith
- Status changed from New to In Progress
This is caused by the introduction of the error_highlight gem in Ruby 3.1. You can prove this to yourself by running the following code in the Rails console:
u = User.first
begin
u.update!({"foo": 8})
rescue => exc
exc
end
If you run it normally, the exception message should look like the one in the issue description. If you start the Rails console with RUBYOPT=--disable-error_highlight
, it goes away and looks like the tests were written to expect.
I think the right approach is to set RUBYOPT when we run tests or in production. This feature is meant to aid development, so we don't need it in production. And if we disable it in production, we should disable it when we run tests too, so clients see the same behavior they would see in production.
I think we should also disable the did_you_mean
gem while we're at it, for basically the same reasons.
I have confirmed that passing unrecognized --disable-
options in RUBYOPT
only issues a warning, so we can set this unconditionally without worrying about the Ruby version.
Updated by Brett Smith about 1 month ago
- Subject changed from arvadosclient tests can fail if RailsAPI errors include backtrace info to arvadosclient tests can fail if Ruby has error_highlight
Updated by Brett Smith about 1 month ago
22407-railsapi-rubyopt @ da6d4f1fee730e9074e630d0c92af80bad880b71 - developer-run-tests: #4581
I found a better place to set RUBYOPT
so we don't have to duplicate it and keep it in sync across multiple files. Aside from that, it's the strategy discussed above, for the reasons above.
- All agreed upon points are implemented / addressed.
- Yes
- Anything not implemented (discovered or discussed during work) has a follow-up story.
- N/A
- Code is tested and passing, both automated and manual, what manual testing was done is described
- See above. Added a test for the configuration itself. Also makes the
sdk/go/arvadosclient
tests pass on my development system.
- See above. Added a test for the configuration itself. Also makes the
- Documentation has been updated.
- N/A
- Behaves appropriately at the intended scale (describe intended scale).
- No change in scale
- Considered backwards and forwards compatibility issues between client and server.
- If anything this probably fixes unintentional backwards compatibility breaks, if you consider specific error message text to be part of the API.
- Follows our coding standards and GUI style guidelines.
- Yes
Updated by Brett Smith about 1 month ago
- Subject changed from arvadosclient tests can fail if Ruby has error_highlight to Ruby 3.1+ can munge error messages returned by RailsAPI
Updated by Brett Smith about 1 month ago
- Status changed from In Progress to Resolved
Applied in changeset arvados|eb878e8e250ee370bb165cb9f41b464f79bd2c9b.