How to find which code is generating a warning?

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)

┌ 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.)

2 Likes

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

3 Likes

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. :frowning:

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

1 Like

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

@eval Base.CoreLogging macro info(args...) end
1 Like

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

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

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.

1 Like

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?

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

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.

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?

1 Like