refactor: consolidate fx event error description into single function
This commit is contained in:
@@ -20,32 +20,17 @@ func (fxLogger) LogEvent(event fxevent.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func describeFXEventError(event fxevent.Event) (string, map[string]any, error) {
|
func describeFXEventError(event fxevent.Event) (string, map[string]any, error) {
|
||||||
if ok, eventName, fields, err := describeFXExecutionEventError(event); ok {
|
|
||||||
return eventName, fields, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return describeFXLifecycleEventError(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func describeFXExecutionEventError(event fxevent.Event) (bool, string, map[string]any, error) {
|
|
||||||
switch e := event.(type) {
|
switch e := event.(type) {
|
||||||
case *fxevent.Provided:
|
case *fxevent.Provided:
|
||||||
return true, "fx_provide_failed", map[string]any{"constructor": e.ConstructorName}, e.Err
|
return "fx_provide_failed", map[string]any{"constructor": e.ConstructorName}, e.Err
|
||||||
case *fxevent.Invoked:
|
case *fxevent.Invoked:
|
||||||
return true, "fx_invoke_failed", map[string]any{"function": e.FunctionName}, e.Err
|
return "fx_invoke_failed", map[string]any{"function": e.FunctionName}, e.Err
|
||||||
case *fxevent.Run:
|
case *fxevent.Run:
|
||||||
return true, "fx_run_failed", map[string]any{"function": e.Name, "kind": e.Kind}, e.Err
|
return "fx_run_failed", map[string]any{"function": e.Name, "kind": e.Kind}, e.Err
|
||||||
case *fxevent.OnStartExecuted:
|
case *fxevent.OnStartExecuted:
|
||||||
return true, "fx_on_start_failed", map[string]any{"caller": e.CallerName, "function": e.FunctionName, "runtime": e.Runtime}, e.Err
|
return "fx_on_start_failed", map[string]any{"caller": e.CallerName, "function": e.FunctionName, "runtime": e.Runtime}, e.Err
|
||||||
case *fxevent.OnStopExecuted:
|
case *fxevent.OnStopExecuted:
|
||||||
return true, "fx_on_stop_failed", map[string]any{"caller": e.CallerName, "function": e.FunctionName, "runtime": e.Runtime}, e.Err
|
return "fx_on_stop_failed", map[string]any{"caller": e.CallerName, "function": e.FunctionName, "runtime": e.Runtime}, e.Err
|
||||||
default:
|
|
||||||
return false, "", nil, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func describeFXLifecycleEventError(event fxevent.Event) (string, map[string]any, error) {
|
|
||||||
switch e := event.(type) {
|
|
||||||
case *fxevent.Started:
|
case *fxevent.Started:
|
||||||
return "fx_start_failed", nil, e.Err
|
return "fx_start_failed", nil, e.Err
|
||||||
case *fxevent.Stopped:
|
case *fxevent.Stopped:
|
||||||
|
|||||||
Reference in New Issue
Block a user