Editing Topic: RCR219 Project: RCR | RCRchive home

RCR 219: add Kernel.warn!() for warnings with backtraces

submitted by discordantus on Sun Feb 22 2004 10:09:56 PM -0800

Status: pending


Abstract

There should be a Kernel method warn!(), a variation of Kernel.warn() which would print out a backtrace for debugging purposes.

Problem

It is often useful to know the exact point in your script from which a warning was issued. Currently, there is no standard method or framework for doing this.

Proposal

There should be a method added to the Kernel module, which prints not only the warning, but the location in the script that caused the warning.

Analysis

Usually, the bang at the end of a method name indicates that the object will be modified. You can extend that to imply danger, or something done more throughly. Kernel.warn!() implies both of these, as warnings given in this way would be for more dangerous conditions (though not warranting an exception) and would more thoroughly report the error (by including a backtrace).

Implementation

I imagine it would probably be written into the Kernel module, but here's an example of how it might be done in standard Ruby.
module Kernel
    def warn!(warning)
        warn( "Warning: #{warning}\n"+
            caller.map{|a|' '*8+"from "+a}.join("\n")
        )
    end
end


Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog