[erlang-questions] erl_syntax[_lib] error handling

Tuncer Ayaz tuncer.ayaz@REDACTED
Sat Apr 19 16:27:08 CEST 2014

On Sat, Apr 19, 2014 at 1:39 PM, Richard Carlsson wrote:
> On 2014-02-24 21:21 , Tuncer Ayaz wrote:
> >
> > erl_syntax and erl_syntax_lib seem to favor throwing exceptions
> > over returning error terms. I found this hard to use due to the
> > missing documenation of what exceptions can be thrown by each
> > function. Only erl_syntax_lib:analyze_application/1 documents one
> > exception it might throw, and the documentation for other funs
> > just states the following: "An exception is thrown if..."
> >
> > The only way to handle erl_syntax[_lib] errors I've seen so far is
> > to catch all exceptions, but that can filter/suppress any kind of
> > exception.
> >
> > What's the recommended way to handle erl_syntax[_lib] errors?
> Hi Tuncer. erl_syntax does not try to be systematic about what kind
> of exception gets generated when the input is bad; that would
> probably make the code grow by 50% In general, it will be a
> function_clause, case_clause or badmatch, but there's no good way of
> separating these from an actual bug in erl_syntax. The intended way
> to use erl_syntax with unknown input is to use the type/1 function
> (throws badarg error if it's not a valid AST) and predicates like
> is_atom/1 to test the input before trying to deconstruct it.

I see. We'll eventually have to revisit rebar_erlc_compiler's use[1]
of erl_syntax[_lib], so I've been looking for ways to parse
differently or not suppress all exceptions.

[1] https://github.com/rebar/rebar/blob/8edaa08b/src/rebar_erlc_compiler.erl#L653-L661

More information about the erlang-questions mailing list