private static object RunActionHandler(ModEntry mod, DllMeta dll, ActionDef act) { try { var lib = ModPhases.LoadDll(mod, dll.Path); if (lib == null) { return(false); } var handler = ActionMods[dll]; object GetParamValue(ParameterInfo pi) => ParamValue(act, pi, mod, handler); object result; foreach (var type in dll.Methods["ActionMod"]) { result = ModPhases.CallInit(mod, lib, type, "ActionMod", GetParamValue); if (result is bool success) { if (success) { return(true); } } else if (result is Exception ex) { LogActionError(handler.Log(), act, ex); if (InList(act.GetText("onerror"), "continue")) { continue; } if (InList(act.GetText("onerror"), "skip")) { return(null); } mod.Log().Info("Aborting Actions. Set OnError to \"Log,Continue\" or \"Log,Skip\" to ignore the error."); return(ex); } else if (result != null) { handler.Log().Error("Unexpected ActionMod result: {0}", result.GetType()); } } return(null); } catch (Exception ex) { mod.Error(ex); return(null); } }
private static void LogActionError(Logger log, ActionDef act, Exception err) { var directives = act.GetText("onerror", "log"); if (InList(directives, "log") || InList(directives, "error")) { log.Error(err); } else if (InList(directives, "warn")) { log.Warn(err); } else if (InList(directives, "info")) { log.Info(err); } else if (InList(directives, "verbo")) { log.Verbo(err); } }