Skip to content
This repository
Browse code

Fix "File not found" error

When a custom tags implementing module is defined in `custom_tags_modules`,
don't throw an exception if the `custom_tags_dir` doesn't contain the file
implementing the custom tag.
  • Loading branch information...
commit cf081931ebe1cf06382a913ff380d2812af4bfe9 1 parent 6e7bb36
Serge Aleynikov authored October 28, 2012

Showing 1 changed file with 21 additions and 10 deletions. Show diff stats Hide diff stats

  1. 31  src/erlydtl_compiler.erl
31  src/erlydtl_compiler.erl
@@ -353,16 +353,26 @@ custom_tags_clauses_ast1([Tag|CustomTags], ExcludeTags, ClauseAcc, InfoAcc, Cont
353 353
             custom_tags_clauses_ast1(CustomTags, ExcludeTags, ClauseAcc, InfoAcc, Context, TreeWalker);
354 354
         false ->
355 355
             CustomTagFile = full_path(Tag, Context#dtl_context.custom_tags_dir),
356  
-            case parse(CustomTagFile, Context) of
357  
-                {ok, DjangoParseTree, CheckSum} ->
358  
-                    {{BodyAst, BodyAstInfo}, TreeWalker1} = with_dependency({CustomTagFile, CheckSum}, 
359  
-                        body_ast(DjangoParseTree, Context, TreeWalker)),
360  
-                    Clause = erl_syntax:clause([erl_syntax:string(Tag), erl_syntax:variable("_Variables"), options_ast()],
  356
+            case filelib:is_file(CustomTagFile) of
  357
+                true ->
  358
+                    case parse(CustomTagFile, Context) of
  359
+                        {ok, DjangoParseTree, CheckSum} ->
  360
+                            {{BodyAst, BodyAstInfo}, TreeWalker1} =
  361
+                                with_dependency({CustomTagFile, CheckSum}, 
  362
+                                    body_ast(DjangoParseTree, Context, TreeWalker)),
  363
+                            Clause = erl_syntax:clause(
  364
+                                [erl_syntax:string(Tag),
  365
+                                 erl_syntax:variable("_Variables"), options_ast()],
361 366
                                 none, [BodyAst]),
362  
-                    custom_tags_clauses_ast1(CustomTags, [Tag|ExcludeTags], [Clause|ClauseAcc], merge_info(BodyAstInfo, InfoAcc), 
363  
-                        Context, TreeWalker1);
364  
-                Error ->
365  
-                    throw(Error)
  367
+                            custom_tags_clauses_ast1(CustomTags, [Tag|ExcludeTags],
  368
+                                [Clause|ClauseAcc], merge_info(BodyAstInfo, InfoAcc), 
  369
+                                Context, TreeWalker1);
  370
+                        Error ->
  371
+                            throw(Error)
  372
+                    end;
  373
+                false ->
  374
+                    custom_tags_clauses_ast1(CustomTags, [Tag | ExcludeTags],
  375
+                        ClauseAcc, InfoAcc, Context, TreeWalker)
366 376
             end
367 377
     end.
368 378
 
@@ -1278,7 +1288,8 @@ custom_tags_modules_ast(Name, InterpretedArgs, #dtl_context{ custom_tags_modules
1278 1288
         I ->
1279 1289
             throw({unsupported_custom_tag_fun, {Module, Name, I}})
1280 1290
     catch _:function_clause ->
1281  
-        custom_tags_modules_ast(Name, InterpretedArgs, Context#dtl_context{ custom_tags_modules = Rest })
  1291
+        custom_tags_modules_ast(Name, InterpretedArgs,
  1292
+            Context#dtl_context{ custom_tags_modules = Rest })
1282 1293
     end.
1283 1294
 
1284 1295
 print(true, Fmt, Args) ->

0 notes on commit cf08193

Please sign in to comment.
Something went wrong with that request. Please try again.