# How to find which code is generating a warning?

**URL:** https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541
**Category:** New to Julia
**Created:** [July 7, 2025, 5:09pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541 "2025-07-07T17:09:24Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![orebas](https://avatars.discourse-cdn.com/v4/letter/o/bbe5ce/32.png) [@orebas](https://discourse.julialang.org/u/orebas)
#### Post date: [July 7, 2025, 5:09pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/1 "2025-07-07T17:09:24Z")

</div>

Some code in my package is generating the below warning. (Actually I think it’s probably 10-20 places). Presumably this is how I’m supposed to learn that I have to update my code. How do I get a list of the problematic call sites? (meaning, which lines in my package are causing these warnings, as opposed to the code in MTK which generates the warning)

```julia
┌ Warning: `ODEProblem(sys, u0, tspan, p; kw...)` is deprecated. Use
│ `ODEProblem(sys, merge(u0, p), tspan)` instead.
└ @ ModelingToolkit ~/.julia/packages/ModelingToolkit/xkwpH/src/deprecations.jl:34

```

(For reference, I asked two strong AIs, and got two wrong answers. Specifically, running Julia with --depwarn=error or --depwarn=yes seemed to have no effect.)

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 7, 2025, 7:25pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/2 "2025-07-07T19:25:54Z")

</div>

@Lilith posted a trick to do this here by turning those warnings into errors:

> [@Warning stack trace](https://discourse.julialang.org/t/warning-stack-trace/67516/2):
>
> 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\> 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: Argu…

---

<div class="post-metadata">

### Author: ![orebas](https://avatars.discourse-cdn.com/v4/letter/o/bbe5ce/32.png) [@orebas](https://discourse.julialang.org/u/orebas)
#### Post date: [July 7, 2025, 8:39pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/3 "2025-07-07T20:39:29Z")

</div>

> [@Warning stack trace](https://discourse.julialang.org/t/warning-stack-trace/67516/2):
>
> ` redirect_stderr(open(touch(tempname()), "r"))`

This is potentially a “neat” trick. Unfortunately, I have some @info statement elsewhere in the code that trigger first. I guess I’m back to grep. ☹

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [July 7, 2025, 8:48pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/4 "2025-07-07T20:48:30Z")

</div>

You could `Pkg.develop` ModelingToolkit and change the deprecation to emit an error instead of a warning.

---

<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: [July 7, 2025, 9:07pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/5 "2025-07-07T21:07:19Z")

</div>

Don’t do this in production or in a package, but you can disable all `@info` statements with

```julia
@eval Base.CoreLogging macro info(args...) end

```

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [July 7, 2025, 11:00pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/6 "2025-07-07T23:00:12Z")

</div>

You can probably define a custom logger that prints the stack trace or throws an error on warning.

---

<div class="post-metadata">

### Author: ![VinceNeede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinceneede/32/215744_2.png) [@VinceNeede](https://discourse.julialang.org/u/VinceNeede)
#### Post date: [July 7, 2025, 11:27pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/7 "2025-07-07T23:27:35Z")

</div>

You can use `LoggingExtras` with a filter, this should allow you to modify the warning by adding a stacktrace

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [July 8, 2025, 3:25am UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/8 "2025-07-08T03:25:06Z")

</div>

Not about warnings in general, but deprecation warnings are specifically about API, so if the deprecated call is really not written in a dependency (in which case it’s their fault, not yours), then a plain text search of `"ODEProblem("` can identify the files and line numbers with your calls and you can make the changes accordingly.

Since you said this happens in several places, you probably don’t want to turn warnings into runtime errors that you’d have to encounter and fix one at a time. It would be nice for a logger to store stack traces for warnings.

---

<div class="post-metadata">

### Author: ![orebas](https://avatars.discourse-cdn.com/v4/letter/o/bbe5ce/32.png) [@orebas](https://discourse.julialang.org/u/orebas)
#### Post date: [July 22, 2025, 6:52pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/9 "2025-07-22T18:52:58Z")

</div>

These are all nice ideas, but I would love to help future Julia users. I would like to add a feature request somewhere so that warnings do something a little smarter (like a global option to show full stacktrade, and the short version hints at it.) I don’t even know where to ask? Is this Julia base? Is it in MTK? Is it actually one of the logging packages? (Obviously this will be low priority, but should probably be on a feature queue somewhere.) Any ideas?

---

<div class="post-metadata">

### Author: ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)
#### Post date: [July 22, 2025, 7:12pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/10 "2025-07-22T19:12:28Z")

</div>

I believe these are from the base `@deprecate` macro. There are two open issues relevant to this thread:

- [depwarn warnings should show location of the problem · Issue #19686 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/19686)
- [Deprecation warnings that warn only when the deprecated call is directly "your fault" · Issue #49583 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/49583)

The second issue has some discussion about the performance downsides of that particular solution, but the first issue hasn’t been active for a long while and is perhaps worth reviving.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [July 22, 2025, 7:27pm UTC](https://discourse.julialang.org/t/how-to-find-which-code-is-generating-a-warning/130541/11 "2025-07-22T19:27:16Z")

</div>

> [@orebas](#):
>
> I would like to add a feature request somewhere so that warnings do something a little smarter (like a global option to show full stacktrade, and the short version hints at it.) I don’t even know where to ask? Is this Julia base? Is it in MTK?

Julia already has `--depwarn=error`, so, if that option has no effect as you say, I’d open an issue on the MTK Github.

Specifically, I think the issue is that MTK uses `@warn` instead of `@deprecate` or `depwarn`?
