# Reporting errors with source code position?

**URL:** <https://discourse.julialang.org/t/reporting-errors-with-source-code-position/38288>\
**Category:** General Usage\
**Tags:** macros, metaprogramming\
**Created:** [April 27, 2020, 8:54am UTC](https://discourse.julialang.org/t/reporting-errors-with-source-code-position/38288 "2020-04-27T08:54:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [April 27, 2020, 8:54am UTC](https://discourse.julialang.org/t/reporting-errors-with-source-code-position/38288/1 "2020-04-27T08:54:52Z")

</div>

Is there any standard rules for reporting errors when metaprogramming?

For the cases that users give wrong data in runtime or they do not properly use a macro, I want to report them the concrete error message with accurate source code position.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 27, 2020, 12:56pm UTC](https://discourse.julialang.org/t/reporting-errors-with-source-code-position/38288/2 "2020-04-27T12:56:05Z")

</div>

Macros will be expanded in the relevant location, so this should happen automatically: for `throw` you get a stacktrace, for `@error` the location should be in the logs (with the defaults).

---

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [April 27, 2020, 1:56pm UTC](https://discourse.julialang.org/t/reporting-errors-with-source-code-position/38288/3 "2020-04-27T13:56:59Z")

</div>

The macro wrapped expression can be large. The error can only automatically located to the macro callsites, but more accurate report should be handled manually.

---

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [April 27, 2020, 2:02pm UTC](https://discourse.julialang.org/t/reporting-errors-with-source-code-position/38288/4 "2020-04-27T14:02:11Z")

</div>

Besides, some errors can also be detected before finishing the macro transformation, and in the case I think it impossible for errors to get automatically and properly reported.
