From 77a6fe86a853f97050bfdd994687223ddf1cece3 Mon Sep 17 00:00:00 2001 From: bd_ Date: Wed, 20 Sep 2023 19:16:42 +0900 Subject: [PATCH] feat: add on-exception callback --- Editor/API/BuildContext.cs | 4 ++++ Editor/API/Fluent/Plugin.cs | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Editor/API/BuildContext.cs b/Editor/API/BuildContext.cs index f043b02..4c682fe 100644 --- a/Editor/API/BuildContext.cs +++ b/Editor/API/BuildContext.cs @@ -237,6 +237,10 @@ internal void RunPass(ConcretePass pass) { pass.Execute(this); } + catch (Exception e) + { + pass.Plugin.OnUnhandledException(e); + } finally { Profiler.EndSample(); diff --git a/Editor/API/Fluent/Plugin.cs b/Editor/API/Fluent/Plugin.cs index 1d8f6a7..9fcff2a 100644 --- a/Editor/API/Fluent/Plugin.cs +++ b/Editor/API/Fluent/Plugin.cs @@ -3,6 +3,7 @@ using System; using System.Threading; using nadena.dev.ndmf.fluent; +using UnityEngine; #endregion @@ -14,6 +15,8 @@ internal interface IPlugin string DisplayName { get; } void Configure(PluginInfo info); + + void OnUnhandledException(Exception e); } public abstract class Plugin : IPlugin where T : Plugin, new() @@ -54,5 +57,22 @@ protected Sequence InPhase(BuildPhase phase) return _info.NewSequence(phase); } + + /// + /// Invoked when a pass in this plugin throws an exception. This exception can be passed to a plugin's own error + /// handling UI. + /// + /// This API will likely be deprecated once a native error-reporting system is available. + /// + /// + protected virtual void OnUnhandledException(Exception e) + { + Debug.LogException(e); + } + + void IPlugin.OnUnhandledException(Exception e) + { + OnUnhandledException(e); + } } } \ No newline at end of file