socketry / console

MIT License
52 stars 13 forks source link

How to disable pretty warnings? #63

Closed rmosolgo closed 2 weeks ago

rmosolgo commented 2 weeks ago

Hi!

I have a bunch of tests in GraphQL-Ruby and in some CI runs, I bundle the async gem. Today, some tests started failing because instead of warnings going to STDERR, they were disappearing. (My tests were making sure that GraphQL-Ruby emits warnings in certain scenarios.)

I have found that locking console to v1.27.0 makes my tests pass again, so I'm guessing the change was caused by https://github.com/socketry/console/commit/6724270f07ae5d62067586a94a7e76a3e418a459.

Is there any way to turn off Console globally? I don't really want it in my project, but it's bundled along with async.

I can fix this problem by adding an explicit version lock to my gemfiles that include async, but I assume it's only a matter of time until that setup doesn't work anymore (whenever Async depends on Console v2).

Or, is there another way that I can keep the "boring" warn(...) behavior? Thanks!

ioquatix commented 2 weeks ago

I basically agree with you and want to remove the console gem dependency from async if possible.

I do want to handle warnings gracefully with the console gem if possible.

I was trying to use Kernel#warn to pass rich objects to the logging backend, but unfortunately it's basically impossible as of now: https://bugs.ruby-lang.org/issues/20864

I think what I'm going to do is define my own defacto extension to Warning, e.g. Warning.log(*arguments, **options), and provide a default implementation that invokes Warning.warn(...). Then, in the console gem, I'll override it. I can't think of anything better.

ioquatix commented 2 weeks ago

So, as a first step, I'm not going to make the warning redirection the default behaviour. I agree, it's a bit surprising, even if I don't mind it.

Then, I'm going to try and de-couple async from console. I'll provide custom shim for emitting warnings and use Console if it's available, otherwise Kernel#warn. I think this is good enough.

ioquatix commented 2 weeks ago

In v1.29 the warn formatting is now not enabled by default, unless you include console/warn.

rmosolgo commented 1 week ago

Thanks... my tests are green again!

ioquatix commented 1 week ago

Thanks for reporting back, and apologies about messing up your CI. It was a bit of a rabbit hole.