# How to make warning into error?

**URL:** <https://discourse.julialang.org/t/how-to-make-warning-into-error/5251>\
**Category:** General Usage\
**Tags:** build, error, travis, warning\
**Created:** [August 6, 2017, 11:26pm UTC](https://discourse.julialang.org/t/how-to-make-warning-into-error/5251 "2017-08-06T23:26:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:56pm UTC](https://discourse.julialang.org/t/how-to-make-warning-into-error/5251/5 "2022-12-01T23:56:32Z")

</div>

Julia doesn’t “throw” warnings. However, warning messages are typically written to the `stderr` stream, so you can turn such warnings to errors simply by redirecting `stderr` to a read-only stream:

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

julia> @warn "foo"
ERROR: ArgumentError: write failed, IOStream is not writeable

```

Originally posted by [@stevengj](https://discourse.julialang.org/u/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)

* * *

Or, you can install a custom logger that turns warnings into errors:

```julia
julia> using Logging, LoggingExtras

julia> error_on_warning = EarlyFilteredLogger(global_logger()) do log_args
           if log_args.level >= Logging.Warn
               error(log_args)
           end
           return true
       end;

julia> global_logger(error_on_warning);

```

Adapted from @fredrikekre’s answer [here](https://discourse.julialang.org/t/terminate-after-warning-is-thrown-global-setting/80368/3)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-make-warning-into-error/5251)._
