# Warning stack trace

**URL:** <https://discourse.julialang.org/t/warning-stack-trace/67516>\
**Category:** General Usage\
**Created:** [September 1, 2021, 4:25pm UTC](https://discourse.julialang.org/t/warning-stack-trace/67516 "2021-09-01T16:25:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [December 1, 2022, 11:58pm UTC](https://discourse.julialang.org/t/warning-stack-trace/67516/2 "2022-12-01T23:58:58Z")

</div>

Julia doesn’t store stack traces for warnings. However, warning messages are typically written to the `stderr` stream, so you can turn such warnings to errors (which do have stack traces) by redirecting `stderr` to a read-only stream:

```julia
julia> redirect_stderr(open(touch(tempname()), "r"))
IOStream(<file ...>)

julia> f() = @warn "Find me"
f (generic function with 1 method)

julia> g() = f()
g (generic function with 1 method)

julia> h() = g()
h (generic function with 1 method)

julia> h()
ERROR: ArgumentError: write failed, IOStream is not writeable
Stacktrace:
  [1] unsafe_write(s::IOStream, p::Ptr{UInt8}, nb::UInt64)
    @ Base ./iostream.jl:373
  [2] unsafe_write
    @ ./io.jl:685 [inlined]
  [3] write(s::IOStream, a::Vector{UInt8})
    @ Base ./io.jl:708
  [4] handle_message(logger::Logging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message::Any, _module::Any, group::Any, id::Any, filepath::Any, line::Any; kwargs::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
    @ Logging ~/.julia/dev/julia/usr/share/julia/stdlib/v1.10/Logging/src/ConsoleLogger.jl:178
  [5] handle_message(logger::Logging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message::Any, _module::Any, group::Any, id::Any, filepath::Any, line::Any)
    @ Logging ~/.julia/dev/julia/usr/share/julia/stdlib/v1.10/Logging/src/ConsoleLogger.jl:106
  [6] macro expansion
    @ ./logging.jl:330 [inlined]
  [7] f()
    @ Main ./REPL[11]:1
  [8] g
    @ ./REPL[12]:1 [inlined]
  [9] h()
    @ Main ./REPL[13]:1
 [10] top-level scope
    @ REPL[14]:1

```

Originally posted by @stevengj in [Terminate after warning is thrown - global setting - #2 by stevengj](https://discourse.julialang.org/t/terminate-after-warning-is-thrown-global-setting/80368/2)

With a bit more work you could create a custom logger that prints the stack-trace without throwing, but this was enough for my use case.

---

_[View the full topic](https://discourse.julialang.org/t/warning-stack-trace/67516)._
