Skip to content

Commit

Permalink
warn: remove depth keyword, no backtraces; warn(err::Exception).
Browse files Browse the repository at this point in the history
Since it's completely unclear what this does or how to use it, I'm
deleting this feature. When `depth=0` backtraces seem to show, while
when `depth=1` they don't or something like that. Now we just don't
ever show backtraces for warnings. This keyword didn't do anything
for the info function since we never print backtraces there.

Also added a warn(err::Exception) method that prints an error the
way it would look if allowed to kill the current task, but doesn't
actually kill the current task. This is useful if catch an error
and want to show it to the user but continue running.
  • Loading branch information
StefanKarpinski committed Oct 13, 2013
1 parent 29c8f3c commit 0e37602
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
4 changes: 2 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ macro deprecate(old,new)
Expr(:toplevel,
Expr(:export,esc(old)),
:(function $(esc(old))(args...)
warn_once(string($oldname," is deprecated, use ",$newname," instead."); depth=1)
warn_once(string($oldname," is deprecated, use ",$newname," instead."))
$(esc(new))(args...)
end))
elseif isa(old,Expr) && old.head == :call
Expand All @@ -14,7 +14,7 @@ macro deprecate(old,new)
Expr(:toplevel,
Expr(:export,esc(old.args[1])),
:($(esc(old)) = begin
warn_once(string($oldcall," is deprecated, use ",$newcall," instead."); depth=1)
warn_once(string($oldcall," is deprecated, use ",$newcall," instead."))
$(esc(new))
end))
else
Expand Down
24 changes: 6 additions & 18 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,13 @@ print_with_color(color::Symbol, msg::String...) =

# use colors to print messages and warnings in the REPL

function info(msg::String...; depth=0)
#stack::Range1{Int} = 3 +
# if isa(depth,Int)
# depth:depth
# else
# depth
# end
with_output_color(print, :blue, STDERR, "INFO: ", msg...)
#with_output_color(show_backtrace, :blue, STDERR, backtrace(), stack)
function info(msg::String...; prefix="INFO: ")
with_output_color(print, :blue, STDERR, prefix, chomp(string(msg...)))
println(STDERR)
end
function warn(msg::String...; depth=0)
stack::Range1{Int} = 2 +
if isa(depth,Int)
depth:depth
else
depth
end
with_output_color(print, :red, STDERR, "WARNING: ", msg...)
with_output_color(show_backtrace, :red, STDERR, backtrace(), stack)
function warn(msg::String...; prefix="WARNING: ")
with_output_color(print, :red, STDERR, prefix, chomp(string(msg...)))
println(STDERR)
end
warn(err::Exception; prefix="ERROR: ") =
warn(sprint(io->showerror(io,err)), prefix=prefix)
4 changes: 2 additions & 2 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ end
# print a warning only once

const have_warned = Dict()
function warn_once(msg::String...; depth=0)
function warn_once(msg::String...)
msg = bytestring(msg...)
haskey(have_warned,msg) && return
have_warned[msg] = true
warn(msg; depth=depth+1)
warn(msg)
end

# BLAS utility routines
Expand Down

3 comments on commit 0e37602

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pity; it was handy to be able to see where deprecation warnings were coming from. I think this was helpful to package authors updating their code.

@StefanKarpinski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with reinstating it but it should have an interface that makes sense and is documented. I was unable to figure out how to disable backtraces altogether despite spending a fair chunk of time looking at this code. Also, the code for showing warnigs and errors is kind of a hot mess – this stuff is spread all over the place: error.jl, client.jl, repl.jl, show.jl; there's probably even more places.

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depth indicates which levels of the backtrace to print. It can be a number which is used to guess the callers frame by addin one each step, or a range, or a list. Sufficiently large or small numbers should prevent any backtrace. Ideally, we could insert this information at compile time via FILE or something, but I'm not clear how that could be made feasible.

Please sign in to comment.