pancsta / asyncmachine-go

AOP Actor Model for distributed workflows
https://asyncmachine.dev
MIT License
72 stars 0 forks source link

feat(machine): add AddErrState and unified stack traces #111

Closed pancsta closed 2 months ago

pancsta commented 2 months ago

Error handing is finally a thing, as pkg/rpc uses sentinel errors to trigger error states. Stack traces are nicely trimmed and logged.

func (h *handlers) ExceptionState(e *am.Event) {
    // call super
    h.ExceptionHandler.ExceptionState(e)
    mach := e.Machine
    err := e.Args["err"].(error)

    // handle sentinel errors to states
    if errors.Is(err, ErrNetwork) || errors.Is(err, ErrNetworkTimeout) {
        mach.Add1(ss.ErrNetwork, nil)
    } else if errors.Is(err, ErrInvalidParams) {
        mach.Add1(ss.ErrRpc, nil)
    } else if errors.Is(err, ErrInvalidResp) {
        mach.Add1(ss.ErrRpc, nil)
    } else if errors.Is(err, ErrRpc) {
        mach.Add1(ss.ErrRpc, nil)
    }
}