diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-12-18 22:04:44 -0500 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-12-18 22:04:44 -0500 |
commit | d201d7f4a6e6058c272fe75bb832dc78a418272f (patch) | |
tree | 0150b76c1b460e35f29ee98fdf43c8a0cfcbd748 /src/rebar_templater.erl | |
parent | 21ae3145dfd9f24af9df962fcbf00fdb55d9b923 (diff) |
A bad template index does not crash; shows warning
This should fix #955
The test is implicit as a bad index previously silently crashed rebar3.
By adding the bad index to the `new` suite's files, we can show that
things keep running.
Diffstat (limited to 'src/rebar_templater.erl')
-rw-r--r-- | src/rebar_templater.erl | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index c7fb2af..f0b2ce8 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -59,10 +59,14 @@ list_templates(State) -> %% Expand a single template's value list_template(Files, {Name, Type, File}, State) -> - TemplateTerms = consult(load_file(Files, Type, File)), - {Name, Type, File, - get_template_description(TemplateTerms), - get_template_vars(TemplateTerms, State)}. + case consult(load_file(Files, Type, File)) of + {error, Reason} -> + {error, {consult, File, Reason}}; + TemplateTerms -> + {Name, Type, File, + get_template_description(TemplateTerms), + get_template_vars(TemplateTerms, State)} + end. %% Load up the template description out from a list of attributes read in %% a .template file. @@ -338,8 +342,10 @@ consult(Cont, Str, Acc) -> {done, Result, Remaining} -> case Result of {ok, Tokens, _} -> - {ok, Term} = erl_parse:parse_term(Tokens), - consult([], Remaining, [Term | Acc]); + case erl_parse:parse_term(Tokens) of + {ok, Term} -> consult([], Remaining, [Term | Acc]); + {error, Reason} -> {error, Reason} + end; {eof, _Other} -> lists:reverse(Acc); {error, Info, _} -> |