Skip to content

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

@garthk

Description

@garthk

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:

  • Pass the filename and line number in Decorator.Decorate.Context

  • Pass the full __CALLER__ in Decorator.Decorate.Context

  • try around calling the decorator; rescue; insert the decorator into the stack trace; reraise

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions