Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ New language features
Language changes
----------------

* Function definition arguments are now by default hidden in the backtrace of error messages in the REPL.
To re enable this, you can add `ENV["JULIA_ARGS_BACKTRACE"] = ""` to your `.juliarc` file.

Breaking changes
----------------

Expand Down
17 changes: 16 additions & 1 deletion base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,31 @@ function ip_matches_func(ip, func::Symbol)
return false
end

global last_err = nothing

function display_error(io::IO, er, bt)
global last_err
last_err = er, bt
Base.with_output_color(:red, io) do io
print(io, "ERROR: ")
# remove REPL-related frames from interactive printing
eval_ind = findlast(addr->ip_matches_func(addr, :eval), bt)
if eval_ind != 0
bt = bt[1:eval_ind-1]
end
Base.showerror(io, er, bt)
Base.showerror(IOContext(io, :hide_args_in_signature => !haskey(ENV, "JULIA_ARGS_BACKTRACE")), er, bt)
end
end

"""
Reshows the latest error that the REPL showed.
"""
function show_lasterror()
global last_err
if last_err == nothing
error("no error has yet been shown")
end
display_error(outstream(Base.active_repl), last_err[1], last_err[2])
end

immutable REPLDisplay{R<:AbstractREPL} <: Display
Expand Down
20 changes: 12 additions & 8 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,10 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
nothing
end

# print a method signature tuple for a lambda definition
# if ::hide_args_in_signature is true for the io the
# arguments in the signatures will not be printed
function show_lambda_types(io::IO, li::LambdaInfo)
# print a method signature tuple for a lambda definition
if li.specTypes === Tuple
print(io, li.def.name, "(...)")
return
Expand All @@ -1027,14 +1029,16 @@ function show_lambda_types(io::IO, li::LambdaInfo)
else
print(io, "(::", ft, ")")
end
first = true
print(io, '(')
for i = 2:length(sig) # fixme (iter): `eachindex` with offset?
first || print(io, ", ")
first = false
print(io, "::", sig[i])
if !get(io, :hide_args_in_signature, false)
first = true
print(io, '(')
for i = 2:length(sig) # fixme (iter): `eachindex` with offset?
first || print(io, ", ")
first = false
print(io, "::", sig[i])
end
print(io, ')')
end
print(io, ')')
nothing
end

Expand Down
10 changes: 10 additions & 0 deletions doc/manual/interacting-with-julia.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,13 @@ informational messages in cyan you can add the following to your ``juliarc.jl``

ENV["JULIA_WARN_COLOR"] = :yellow
ENV["JULIA_INFO_COLOR"] = :cyan

Customizing Error Messages
--------------------------

By default Julia will not show the arguments for the functions in a backtrace since this can lead to quite large error messages.
It is possible to activate this by adding the following to your ``juliarc.jl`` file::

ENV["JULIA_ARGS_BACKTRACE"] = ""

The last error message showed in the REPL can be showed again with `Base.REPL.show_lasterror()`.