# system event to catch all failures in the inngest environment
@inngest_client.create_function(
    fn_id="global_failure_handler",
    trigger=[
        TriggerEvent(event="inngest/function.failed"),
        #TriggerEvent(event="inngest/function.cancelled")
    ],
)
async def global_failure_handler(ctx: Context):
    pass # handle all failures, e.g. to send to sentry
```

</GuideSection>

<GuideSection show="go">

```go
// the Go SDK doesn't have native way to define failure handlers,
// but you can define one by create a new function that uses
// the "inngest/function.failed" event and an expression:
myFailureHandler := inngestgo.CreateFunction(
	client,
	inngestgo.FunctionOpts{
			ID:   "account-created-on-failure",
			Name: "Account creation flow: On Failure",
	},
	inngestgo.EventTrigger(
		"inngest/function.failed",
		// The full function_id is a concatenated slug of your app id and the
		// failing function's "ID"
		inngestgo.StrPtr("event.data.function_id == 'my-app-account-created'")
	),
	func(
		ctx context.Context,
		input inngestgo.Input[inngestgo.GenericEvent[functionFailedEventData, any]],
	) (any, error) {
		// Handle your failure here
		return nil, nil
	}
)

type functionFailedEventData struct {
  Error struct {
    Message string `json:"message"`
    Name string `json:"name"`
  } `json:"error"`
  FunctionID string `json:"function_id"`
  RunID string `json:"run_id"`
}

// How to determine the full function_id to use in the expression?
// 1. Get the "app id" set via "NewHandler"
h := inngestgo.NewHandler("my-app", inngestgo.HandlerOpts{})
// 2. Get the FunctionOpts's ID parameter:
f := inngestgo.CreateFunction(
	client,
	inngestgo.FunctionOpts{
			ID:   "account-created",
			Name: "Account creation flow",
	},
	inngestgo.EventTrigger("api/account.created", nil),
	AccountCreated,
)
// 3. Join them with a hyphen:
// event.data.function_id == 'my-app-account-created'
```

</GuideSection>

</GuideSelector>

<Callout>
  To handle cancelled function runs, checkout out [this example](/docs/examples/cleanup-after-function-cancellation) that uses the [`inngest/function.cancelled`](/docs/reference/system-events/inngest-function-cancelled) system event.
</Callout>