improvement: raise helpful errors for DSL section inline and inline+block syntax#214
improvement: raise helpful errors for DSL section inline and inline+block syntax#214
Conversation
| unless section.top_level? && path == [] do | ||
| defmacro unquote(section.name)(body) do | ||
| # Handle mixed syntax - personal_details(opts, do: block) | ||
| defmacro unquote(section.name)(opts, [do: _] = _block) do |
There was a problem hiding this comment.
🤔 what if we actually just could handle both? Do we want to? We could theoretically just call it with just opts and then call it with just do and it should "just work"
There was a problem hiding this comment.
Feel like this question engages the "why are sections and entities separate?" question raised in a previous issue. Could entities handle everything and simplify the logic? I think so
There was a problem hiding this comment.
Possibly but that's a major version bump and an overhaul of the whole Ash ecosystem so I'm not particularly interested in that at the moment 😂
There was a problem hiding this comment.
I've pushed up the same handling for mixed entity syntax which was the issue that @marot originally found which I was doing while travelling.
I've got some other changes coming, so will have a think about whether "just doing it" is better than throwing a helpful error.
Either way, a helpful error is better than the horrible errors users currently get, so would it be worth merging this as is?
There was a problem hiding this comment.
🤔 This is defining a new function just to tell you that you can't call it. If we're going to define a new function that expands the API, and the option exists to make it work, then we should prefer that. If Elixir's undefined function error is confusing then we should fix that.
Currently DSL sections throw confusing error messages for the following DSL declarations: 1. Using inline keyword args instead of block syntax gives ``` ** (Spark.Options.ValidationError) required :first_name option not found, received options: [] ``` 2. Using inline and block syntax throws the following compile error ``` error: undefined function section_name/2 (there is no such import) ``` We now catch these errors and show helpful errors so that the user understands what went wrong and how to fix it. The new errors are as follows: 1. Inline syntax ``` Cannot use inline syntax for DSL section `personal_details`. Use block syntax: `personal_details do ... end`. ``` 2. Mixed inline and block syntax ``` Cannot use both inline syntax and block syntax for DSL section `personal_details`. Use block syntax `personal_details do ... end` ```
50a780c to
d1d796e
Compare
|
Closing as stale. Feedback on the feature add was not being interested in adding new DSL functions just for them to raise an error. |
Currently DSL sections throw confusing error messages for the following DSL declarations:
We now catch these errors and show helpful errors so that the user understands what went wrong and how to fix it. The new errors are as follows: