Arjan Scherpenisse  committed bdfc9f8

Make dispatch rule reloading more stable.

When reloading dispatch rules, crash when there is a syntax error, and
keep the old dispatch rules in this case.

Also show a warning to the user in the admin, and do it only once when
hitting the "reload modules" button, not twice.

Fixes issue 117

  • Participants
  • Parent commits 6c05d9a

Comments (0)

Files changed (2)

File modules/mod_admin_modules/actions/action_admin_modules_module_rescan.erl

 %% @spec event(Event, Context1) -> Context2
 event({postback, {module_rescan, Actions}, _TriggerId, _TargetId}, Context) ->
     z_notifier:notify(module_ready, Context),
-    z_dispatcher:reload(Context),
     Context1 = z_render:growl("Module rescan is in progress.", Context),
     z_render:wire(Actions, Context1).

File src/support/z_dispatcher.erl

 %% @doc Reload the dispatch list and send it to the webmachine dispatcher.
 reload_dispatch_list(#state{context=Context} = State) ->
-    DispatchList = collect_dispatch_lists(Context),
+    DispatchList = try 
+                       collect_dispatch_lists(Context)
+                   catch
+                       _:{error, Msg} ->
+                           z_session_manager:broadcast(#broadcast{type="error", message="Dispatch error! " ++ Msg, title="Dispatcher", stay=false}, Context),
+                           State#state.dispatchlist
+                   end,
     LookupDict = dispatch_for_uri_lookup(DispatchList),
     State#state{dispatchlist=DispatchList, lookup=LookupDict}.
         M:E ->
             ?ERROR("File dispatch error: ~p  ~p", [File, {M,E}]),
-            []
+            throw({error, "Parse error in " ++ z_convert:to_list(File)})