Hyperlinkv0.8.0-beta.28

Runtime

Runtime.defaultTeardownconsteffect/Runtime.ts:117
<E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): void

The default teardown function that determines exit codes from an Effect exit.

When to use

Use as the standard teardown for main programs with conventional process exit codes and support for errorExitCode.

Details

This teardown follows these exit-code rules:

  • 0 for successful completion.
  • 130 for interruption-only failures.
  • The squashed error's errorExitCode value for other failures when present.
  • 1 for other failures.

Gotchas

The 130 code is used only when the Cause contains interruptions and no other failure reasons. Mixed causes use the squashed error path instead.

Example (Referencing default teardown)

import { Exit, Runtime } from "effect"

const logExitCode = (exit: Exit.Exit<any, any>) => {
  Runtime.defaultTeardown(exit, (code) => {
    console.log(`Exit code: ${code}`)
  })
}

logExitCode(Exit.succeed(42))
// Output: Exit code: 0

logExitCode(Exit.fail("error"))
// Output: Exit code: 1

logExitCode(Exit.interrupt(123))
// Output: Exit code: 130
Source effect/Runtime.ts:1178 lines
export const defaultTeardown: Teardown = <E, A>(
  exit: Exit.Exit<E, A>,
  onExit: (code: number) => void
) => {
  if (Exit.isSuccess(exit)) return onExit(0)
  if (Cause.hasInterruptsOnly(exit.cause)) return onExit(130)
  return onExit(getErrorExitCode(Cause.squash(exit.cause)))
}
Referenced by 1 symbols