# Warnings?

**URL:** <https://rubytalk.org/t/warnings/7079>\
**Category:** ruby-talk\
**Created:** [29 July 2003 10:16 UTC](https://rubytalk.org/t/warnings/7079 "2003-07-29T10:16:56Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Bates](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@Tim\_Bates](https://rubytalk.org/u/Tim_Bates)\
**Post date:** [29 July 2003 10:16 UTC](https://rubytalk.org/t/warnings/7079/1 "2003-07-29T10:16:56Z")

</div>

Hi all,  
I’ve recently got around to reinstating some of my old Ruby apps after a  
system upgrade, part of which involved an upgrade from 1.6 to 1.8pre3.  
Some of the libraries used in these apps were written for 1.6, and now  
they spew out loads of warnings. I seem to remember something about  
warnings being on by default in a planned future version of Ruby, but I  
didn’t think it was as soon as 1.8 - however, regardless of whether this  
is the case or not, how do I turn them off? Remember that it’s not my  
code, so I’m not about to go through and correct all the warnings. The  
libraries still function correctly.

Tim Bates

> **···**
>
> –  
> [tim@bates.id.au](mailto:tim@bates.id.au)

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [29 July 2003 16:00 UTC](https://rubytalk.org/t/warnings/7079/2 "2003-07-29T16:00:21Z")

</div>

Hi,

> **···**
>
> In message “Warnings?” on 03/07/29, Tim Bates [tim@bates.id.au](mailto:tim@bates.id.au) writes:
> 
> > I’ve recently got around to reinstating some of my old Ruby apps after a  
> > system upgrade, part of which involved an upgrade from 1.6 to 1.8pre3.  
> > Some of the libraries used in these apps were written for 1.6, and now  
> > they spew out loads of warnings. I seem to remember something about  
> > warnings being on by default in a planned future version of Ruby, but I  
> > didn’t think it was as soon as 1.8 - however, regardless of whether this  
> > is the case or not, how do I turn them off? Remember that it’s not my  
> > code, so I’m not about to go through and correct all the warnings. The  
> > libraries still function correctly.
> 
> You’ve inspired me to add a way to stop all warnings. In the near  
> future release, -W0 stops all warnings.
> 
> ```
> matz.
> 
> ```

---

<div class="post-metadata">

**Author:** ![Michael\_Davis1](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Michael\_Davis1](https://rubytalk.org/u/Michael_Davis1)\
**Post date:** [29 July 2003 19:02 UTC](https://rubytalk.org/t/warnings/7079/3 "2003-07-29T19:02:28Z")

</div>

How about a way to trap warnings similar to rescue Exception so we can trap and suppress certain expected warnings?

Thanks, Michael Davis

Yukihiro Matsumoto wrote:

> **···**
>
> > Hi,
> > 
> > In message “Warnings?” \> on 03/07/29, Tim Bates [tim@bates.id.au](mailto:tim@bates.id.au) writes:
> > 
> > > I’ve recently got around to reinstating some of my old Ruby apps after a  
> > > system upgrade, part of which involved an upgrade from 1.6 to 1.8pre3.  
> > > Some of the libraries used in these apps were written for 1.6, and now  
> > > they spew out loads of warnings. I seem to remember something about  
> > > warnings being on by default in a planned future version of Ruby, but I  
> > > didn’t think it was as soon as 1.8 - however, regardless of whether this  
> > > is the case or not, how do I turn them off? Remember that it’s not my  
> > > code, so I’m not about to go through and correct all the warnings. The  
> > > libraries still function correctly.
> > 
> > You’ve inspired me to add a way to stop all warnings. In the near  
> > future release, -W0 stops all warnings.
> > 
> > ```
> > matz.
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![Tim\_Bates](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@Tim\_Bates](https://rubytalk.org/u/Tim_Bates)\
**Post date:** [29 July 2003 22:12 UTC](https://rubytalk.org/t/warnings/7079/4 "2003-07-29T22:12:26Z")

</div>

What can I do in the meantime? One of my curses-based apps is  
practically unuseable, because the database-backed prints lots of  
warnings every time it does anything. I’d like to have an interim  
solution. 😉

Tim Bates

> **···**
>
> On Wed, Jul 30, 2003 at 01:00:21AM +0900, Yukihiro Matsumoto wrote:
> 
> > You’ve inspired me to add a way to stop all warnings. In the near  
> > future release, -W0 stops all warnings.
> 
> –  
> tim@bates.id.au

---

<div class="post-metadata">

**Author:** ![Paul\_Brannan](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Brannan](https://rubytalk.org/u/Paul_Brannan)\
**Post date:** [30 July 2003 13:48 UTC](https://rubytalk.org/t/warnings/7079/5 "2003-07-30T13:48:30Z")

</div>

How can this feature be accessed from inside Ruby code?

Will it be possible to turn up the warning level? My personal  
preference would be to always use the highest warning level possible.

Paul

> **···**
>
> On Wed, Jul 30, 2003 at 01:00:21AM +0900, Yukihiro Matsumoto wrote:
> 
> > You’ve inspired me to add a way to stop all warnings. In the near  
> > future release, -W0 stops all warnings.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [29 July 2003 19:37 UTC](https://rubytalk.org/t/warnings/7079/6 "2003-07-29T19:37:38Z")

</div>

Hi,

> **···**
>
> In message “Re: Warnings?” on 03/07/30, Michael Davis [mdavis@sevasoftware.com](mailto:mdavis@sevasoftware.com) writes:
> 
> > How about a way to trap warnings similar to rescue Exception so we can trap and suppress certain expected warnings?
> 
> Since warning is a mere message, not exit like exceptions, it is more  
> difficult to catch. You can suppress warning messages by redirecting  
> $stderr temporarily (although it’s not thread safe).
> 
> ```
> matz.
> 
> ```

---

<div class="post-metadata">

**Author:** ![why\_the\_lucky\_stiff1](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@why\_the\_lucky\_stiff1](https://rubytalk.org/u/why_the_lucky_stiff1)\
**Post date:** [29 July 2003 22:46 UTC](https://rubytalk.org/t/warnings/7079/7 "2003-07-29T22:46:04Z")

</div>

$stderr.close

Or:

$stderr = File.open( ‘/var/log/tims-ncurses-app.log’, ‘w’ )

\_why

> **···**
>
> On Tuesday 29 July 2003 04:12 pm, Tim Bates wrote:
> 
> > On Wed, Jul 30, 2003 at 01:00:21AM +0900, Yukihiro Matsumoto wrote:
> > 
> > > You’ve inspired me to add a way to stop all warnings. In the near  
> > > future release, -W0 stops all warnings.
> > 
> > What can I do in the meantime? One of my curses-based apps is  
> > practically unuseable, because the database-backed prints lots of  
> > warnings every time it does anything. I’d like to have an interim  
> > solution. 😉

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [30 July 2003 06:05 UTC](https://rubytalk.org/t/warnings/7079/8 "2003-07-30T06:05:33Z")

</div>

Somewhat far-out, but could AspectR be used to redirect $stderr  
everytime you entered a database function?

martin

> **···**
>
> Tim Bates [tim@bates.id.au](mailto:tim@bates.id.au) wrote:
> 
> > On Wed, Jul 30, 2003 at 01:00:21AM +0900, Yukihiro Matsumoto wrote:
> > 
> > > You’ve inspired me to add a way to stop all warnings. In the near  
> > > future release, -W0 stops all warnings.
> > 
> > What can I do in the meantime? One of my curses-based apps is  
> > practically unuseable, because the database-backed prints lots of  
> > warnings every time it does anything. I’d like to have an interim  
> > solution. 😉

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [30 July 2003 17:33 UTC](https://rubytalk.org/t/warnings/7079/9 "2003-07-30T17:33:31Z")

</div>

Hi,

> How can this feature be accessed from inside Ruby code?

$VERBOSE = nil # to make it silent

> Will it be possible to turn up the warning level? My personal  
> preference would be to always use the highest warning level possible.

$VERBOSE = false # to make it normal level  
$VERBOSE = true # to make it verbose

```
						matz.

```

> **···**
>
> In message “Re: Warnings?” on 03/07/30, Paul Brannan [pbrannan@atdesk.com](mailto:pbrannan@atdesk.com) writes:

---

<div class="post-metadata">

**Author:** ![Michael\_Davis1](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Michael\_Davis1](https://rubytalk.org/u/Michael_Davis1)\
**Post date:** [29 July 2003 23:54 UTC](https://rubytalk.org/t/warnings/7079/10 "2003-07-29T23:54:09Z")

</div>

I can appreciate the difficulty, however, I would rather not suppress all warnings and yet I have code that generates warnings that are okay. Will it be possible to turn off warnings and then turn them back on again at runtime? This would at least provide me an option to disable warning messages during methods that generate warnings.

Thanks, Michael Davis

Yukihiro Matsumoto wrote:

> **···**
>
> > Hi,
> > 
> > In message “Re: Warnings?” \> on 03/07/30, Michael Davis [mdavis@sevasoftware.com](mailto:mdavis@sevasoftware.com) writes:
> > 
> > > How about a way to trap warnings similar to rescue Exception so we can trap and suppress certain expected warnings?
> > 
> > Since warning is a mere message, not exit like exceptions, it is more  
> > difficult to catch. You can suppress warning messages by redirecting  
> > $stderr temporarily (although it’s not thread safe).
> > 
> > ```
> > matz.
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [30 July 2003 02:27 UTC](https://rubytalk.org/t/warnings/7079/11 "2003-07-30T02:27:29Z")

</div>

“Yukihiro Matsumoto” [matz@ruby-lang.org](mailto:matz@ruby-lang.org) schrieb im Newsbeitrag  
news:1059507455.553355.1938.nullmailer@picachu.netlab.jp…

> Hi,
> 
> > How about a way to trap warnings similar to rescue Exception so we can  
> > trap and suppress certain expected warnings?
> 
> Since warning is a mere message, not exit like exceptions, it is more  
> difficult to catch. You can suppress warning messages by redirecting  
> $stderr temporarily (although it’s not thread safe).

The approach most reasonable is IMHO to provide a warning handler setting  
mechanism similarly to the trace handler. Only I don’t know how much  
runtime overhead that’d be. The handler block could receive something like

> level, code, message, sender| and treat it appropriately. -W0, -W1 etc.  
> would then change the block’s filtering according to level.

Or should we use a mature logging feature? Maybe  
[Log4r - Logging system written in Ruby download | SourceForge.net](http://sourceforge.net/projects/log4r/) or a smaller solution. Matz, what do  
you think?

Regards

```
robert

```

> **···**
>
> > In message “Re: Warnings?” \> on 03/07/30, Michael Davis [mdavis@sevasoftware.com](mailto:mdavis@sevasoftware.com) writes:

---

<div class="post-metadata">

**Author:** ![Michael\_Davis1](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Michael\_Davis1](https://rubytalk.org/u/Michael_Davis1)\
**Post date:** [30 July 2003 20:49 UTC](https://rubytalk.org/t/warnings/7079/12 "2003-07-30T20:49:06Z")

</div>

Thanks, this worked great.

Yukihiro Matsumoto wrote:

> **···**
>
> > Hi,
> > 
> > In message “Re: Warnings?” \> on 03/07/30, Paul Brannan [pbrannan@atdesk.com](mailto:pbrannan@atdesk.com) writes:
> > 
> > > How can this feature be accessed from inside Ruby code?
> > 
> > $VERBOSE = nil # to make it silent
> > 
> > > Will it be possible to turn up the warning level? My personal  
> > > preference would be to always use the highest warning level possible.
> > 
> > $VERBOSE = false # to make it normal level  
> > $VERBOSE = true # to make it verbose
> > 
> > ```
> > matz.
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Austin\_Ziegler2](https://rubytalk.org/u/Austin_Ziegler2)\
**Post date:** [30 July 2003 00:38 UTC](https://rubytalk.org/t/warnings/7079/13 "2003-07-30T00:38:13Z")

</div>

This seems to work, at least in irb:

irb(main):001:0\> class WarningException \< Exception; end  
irb(main):002:0\> module Kernel  
irb(main):003:1\> def warn(m)  
irb(main):004:2\> raise WarningException, m  
irb(main):005:2\> end  
irb(main):006:1\> end  
irb(main):007:0\> warn “Hello”  
(irb):4:in `warn': Hello (WarningException) from (irb):7:in `irb\_binding’  
from C:/Apps/Ruby18/lib/ruby/1.8/irb/workspace.rb:52:in  
`irb\_binding’  
from C:/Apps/Ruby18/lib/ruby/1.8/irb/workspace.rb:52

This, of course, depends on the module using the functionality. It  
also won’t work on rb\_warning or rb\_warn, obviously.

-austin

> **···**
>
> On Wed, 30 Jul 2003 08:54:09 +0900, Michael Davis wrote:
> 
> > I can appreciate the difficulty, however, I would rather not suppress all  
> > warnings and yet I have code that generates warnings that are okay. Will  
> > it be possible to turn off warnings and then turn them back on again at  
> > runtime? This would at least provide me an option to disable warning  
> > messages during methods that generate warnings.
> 
> –  
> austin ziegler \* austin@halostatue.ca \* Toronto, ON, Canada  
> software designer \* pragmatic programmer \* 2003.07.29  
> \* 20.31.14

---

<div class="post-metadata">

**Author:** ![Ben\_Giddings](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@Ben\_Giddings](https://rubytalk.org/u/Ben_Giddings)\
**Post date:** [30 July 2003 00:56 UTC](https://rubytalk.org/t/warnings/7079/14 "2003-07-30T00:56:12Z")

</div>

When you say you have “code that generates warnings that are ok”, you  
mean the warnings are safe to ignore, or code that generates warnings  
that looks ok to you? And when you say “turn them back on again at  
runtime”, do you mean a variable you can change programmatically, or a  
function you can run that determines whether warnings go to the console  
or not?

A typical unix way of dealing with output you don’t care about is  
redirecting it to /dev/null, so you could create methods that reassign  
$stderr to the default value or /dev/null depending on whether or not  
you want to see them:

def warningsOn  
$stderr.flush  
$stderr = STDERR  
end

def warningsOff  
$stderr.flush  
$stderr = File.open(‘/dev/null’, ‘w’)  
end

(thinks _why_ for the prototype)

Ben

> **···**
>
> On Tuesday, July 29, 2003, at 07:54 PM, Michael Davis wrote:
> 
> > I can appreciate the difficulty, however, I would rather not suppress  
> > all warnings and yet I have code that generates warnings that are  
> > okay. Will it be possible to turn off warnings and then turn them  
> > back on again at runtime? This would at least provide me an option to  
> > disable warning messages during methods that generate warnings.

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [30 July 2003 02:28 UTC](https://rubytalk.org/t/warnings/7079/15 "2003-07-30T02:28:01Z")

</div>

> The approach most reasonable is IMHO to provide a warning handler setting  
> mechanism similarly to the trace handler. Only I don’t know how much  
> runtime overhead that’d be. The handler block could receive something like
> 
> > level, code, message, sender| and treat it appropriately. -W0, -W1 etc.  
> > would then change the block’s filtering according to level.

I proposed a think like this !  
I’m not alone ! 🙂  
Oh, and a $VERBOSE as

$VERBOSE={ ‘version\_warnings’=\>true,  
‘uninitialized\_vars’=\>false,  
‘redefined\_nethode’=\>true}

well, with more elements:)

> Or should we use a mature logging feature? Maybe  
> [Log4r - Logging system written in Ruby download | SourceForge.net](http://sourceforge.net/projects/log4r/) or a smaller solution. Matz, what do  
> you think?

devel/logger could fit?

> **···**
>
> il Tue, 29 Jul 2003 22:53:41 +0200, “Robert Klemme” [bob.news@gmx.net](mailto:bob.news@gmx.net) ha scritto::
