Skip to content
Browse files

Nice error message on missing legacy library (#85)

  • Loading branch information...
1 parent d61650c commit ee261d4cd4e20fb5e74a886bba0f00e9e4387b78 @kaos kaos committed Mar 1, 2014
Showing with 26 additions and 10 deletions.
  1. +17 −10 src/erlydtl_compiler.erl
  2. +9 −0 tests/src/erlydtl_unittests.erl
View
27 src/erlydtl_compiler.erl
@@ -308,18 +308,25 @@ load_libraries([Lib|Libs], Context) ->
load_libraries(Libs, load_library(Lib, Context)).
load_legacy_filters([], Context) -> Context;
-load_legacy_filters([Mod|Filters], Context) ->
- load_legacy_filters(Filters, add_filters(read_legacy_library(Mod), Context)).
+load_legacy_filters([Mod|Mods], Context) ->
+ {Filters, Context1} = read_legacy_library(Mod, Context),
+ load_legacy_filters(Mods, add_filters(Filters, Context1)).
load_legacy_tags([], Context) -> Context;
-load_legacy_tags([Mod|Tags], Context) ->
- load_legacy_tags(Tags, add_tags(read_legacy_library(Mod), Context)).
-
-read_legacy_library(Mod) ->
- [{Name, {Mod, Name}}
- || {Name, _} <- lists:ukeysort(1, Mod:module_info(exports)),
- Name =/= module_info
- ].
+load_legacy_tags([Mod|Mods], Context) ->
+ {Tags, Context1} = read_legacy_library(Mod, Context),
+ load_legacy_tags(Mods, add_tags(Tags, Context1)).
+
+read_legacy_library(Mod, Context) ->
+ case code:ensure_loaded(Mod) of
+ {module, Mod} ->
+ {[{Name, {Mod, Name}}
+ || {Name, _} <- lists:ukeysort(1, Mod:module_info(exports)),
+ Name =/= module_info
+ ], Context};
+ {error, Reason} ->
+ {[], ?WARN({load_library, '(custom-legacy)', Mod, Reason}, Context)}
+ end.
is_up_to_date(_, #dtl_context{force_recompile = true}) ->
false;
View
9 tests/src/erlydtl_unittests.erl
@@ -1393,6 +1393,15 @@ tests() ->
{{1,10},erlydtl_beam_compiler,{unknown_filter,reverse,1}},
{none,erlydtl_compiler_utils,{load_library,test1,test1,nofile}}
])]
+ },
+ {"pre load unknown legacy library",
+ <<"{% foo %}">>, [], [],
+ [{custom_tags_modules, [foo]}],
+ <<"">>,
+ [error_info(
+ [no_out_dir,
+ {none,erlydtl_compiler,{load_library,'(custom-legacy)',foo,nofile}}
+ ])]
}
]},
{"load",

0 comments on commit ee261d4

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