# How to get a clean stacktrace in v0.6

**URL:** <https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474>\
**Category:** General Usage\
**Created:** [June 26, 2017, 7:04pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474 "2017-06-26T19:04:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 26, 2017, 7:04pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/1 "2017-06-26T19:04:16Z")

</div>

The stacktrace in 0.6 is nicely formatted in the REPL - but when I display it in the browser, it’s unreadable. Can I get a clean representation of the stacktrace?

```julia
Stacktrace:
 [1] e[1mmatch_routese[22me[22me[1m(e[22me[22m::HttpCommon.Request, ::HttpCommon.Response, ::Sessions.Session, ::Router.Params{Any}e[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/Genie/src/Router.jl:462e[22me[22m
 [2] e[1mroute_requeste[22me[22me[1m(e[22me[22m::HttpCommon.Request, ::HttpCommon.Response, ::IPv4e[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/Genie/src/Router.jl:86e[22me[22m
 [3] e[1mhandle_requeste[22me[22me[1m(e[22me[22m::HttpCommon.Request, ::HttpCommon.Response, ::IPv4e[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/Genie/src/AppServer.jl:122e[22me[22m
 [4] e[1m(::AppServer.##1#9)e[22me[22me[1m(e[22me[22m::HttpCommon.Request, ::HttpCommon.Responsee[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/Genie/src/AppServer.jl:25e[22me[22m
 [5] e[1m(::HttpServer.#on_message_complete#14{HttpServer.Server,HttpServer.Client{TCPSocket},Bool})e[22me[22me[1m(e[22me[22m::HttpCommon.Requeste[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/HttpServer/src/HttpServer.jl:427e[22me[22m
 [6] e[1mon_message_completee[22me[22me[1m(e[22me[22m::Ptr{HttpParser.Parser}e[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/HttpServer/src/RequestParser.jl:113e[22me[22m
 [7] e[1mhttp_parser_executee[22me[22me[1m(e[22me[22m::HttpParser.Parser, ::HttpParser.ParserSettings, ::Array{UInt8,1}e[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/HttpParser/src/HttpParser.jl:115e[22me[22m
 [8] e[1mprocess_cliente[22me[22me[1m(e[22me[22m::HttpServer.Server, ::HttpServer.Client{TCPSocket}, ::Boole[1m)e[22me[22m at e[1m/Users/adrian/.julia/v0.6/HttpServer/src/HttpServer.jl:389e[22me[22m
 [9] e[1m(::HttpServer.##7#8{HttpServer.Server,Bool})e[22me[22me[1m(e[22me[22me[1m)e[22me[22m at e[1m./task.jl:335e[22me[22m

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 26, 2017, 7:06pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/2 "2017-06-26T19:06:49Z")

</div>

Either use a regexp to get rid of the ANSI control codes yourself or start julia with `--color=no` (I think).

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 26, 2017, 7:13pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/3 "2017-06-26T19:13:04Z")

</div>

Or alternatively, perhaps there is some javascript library that can format the strings as nice html?

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 26, 2017, 7:13pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/4 "2017-06-26T19:13:50Z")

</div>

In my opinion the error stack should be formatting independent. The error stack is about data, and data should be separated from presentation.

In this case I display it on the web (so I’d want text or HTML). In other cases I log it to a text file (so text). In others, I might want to send it as a JSON response (so JSON). And so on…

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 26, 2017, 7:19pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/5 "2017-06-26T19:19:27Z")

</div>

If you catch the stacktrace you can display it however you want. What you showed is just the way the REPL decides to present it.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 26, 2017, 7:19pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/6 "2017-06-26T19:19:38Z")

</div>

Well, the _data_ doesn’t have the formatting built in, only the default printing to STDERR, IIRC. If you want the StackTrace object for further manipulation, you’ll have to catch the error yourself and not rely on the default printing.  
Also, @kristoffer.carlsson is right, you can parse the ANSI codes (atom-ink does this too, if you wanna have a look).

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 26, 2017, 7:25pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/7 "2017-06-26T19:25:31Z")

</div>

Thanks for your input @pfitzseb and @kristoffer.carlsson

I’m using

```julia
sprint(io->Base.show_backtrace(io, catch_backtrace())

```

to display the error in the browser, in a user friendly way.

`show_stacktrace` is not documented, I found it digging through other sources, looks like that’s the culprit…

I’ve been struggling a lot with getting useful and readable stacktraces and the above was the best option in v0.5. I guess it’s back to the drawing board now in 0.6, I’ll have to just render the raw stacktrace myself.

Thanks!

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 26, 2017, 7:29pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/8 "2017-06-26T19:29:41Z")

</div>

Have a look at [https://github.com/JunoLab/Atom.jl/blob/master/src/display/errors.jl](https://github.com/JunoLab/Atom.jl/blob/master/src/display/errors.jl) for inspiration (you could actually almost take that code verbatim, since it kinda spits out HTML).

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 26, 2017, 7:39pm UTC](https://discourse.julialang.org/t/how-to-get-a-clean-stacktrace-in-v0-6/4474/9 "2017-06-26T19:39:49Z")

</div>

Thanks @pfitzseb, that looks great!
