arjan / decorator

Function decorators for Elixir
MIT License
385 stars 20 forks source link

Can't issue good compile-time errors re bad arguments #41

Open garthk opened 4 years ago

garthk commented 4 years ago

I'm raising because my decorator arguments are bad, and the stack trace isn't giving as much help as I like to provide:

== Compilation error in file lib/my_app/my_module.ex ==
** (ArgumentError) event_name must be made of atoms
    lib/telemetry_decorator.ex:47: anonymous fn/2 in TelemetryDecorator.telemetry/3
    (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/telemetry_decorator.ex:47: TelemetryDecorator.telemetry/3
    lib/decorator/decorate.ex:164: Decorator.Decorate.apply_decorator/3
    (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/decorator/decorate.ex:128: Decorator.Decorate.decorate/4
    (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    expanding macro: Decorator.Decorate.before_compile/1

That not bad as a clue, but it'd be great to put the line number of the decoration in there. I can scrape some from context.args, if there are any; more from body, but I can't get the filename anywhere.

Possible fixes:

I'm happy to raise a PR for either, or some way that you think would be cleaner; what would you feel OK merging?