<E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidThe 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:
0for successful completion.130for interruption-only failures.- The squashed error's errorExitCode value for other failures when present.
1for 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: 130export const const defaultTeardown: TeardownThe 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
defaultTeardown: Teardown = <function (type parameter) E in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidE, function (type parameter) A in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidA>(
exit: Exit.Exit<E, A>exit: import ExitExit.type Exit.Exit = /*unresolved*/ anyExit<function (type parameter) E in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidE, function (type parameter) A in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidA>,
onExit: (code: number) => voidonExit: (code: numbercode: number) => void
) => {
if (import ExitExit.isSuccess(exit: Exit.Exit<E, A>exit)) return onExit: (code: number) => voidonExit(0)
if (import CauseCause.hasInterruptsOnly(exit: Exit.Exit<E, A>(parameter) exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
exit.cause)) return onExit: (code: number) => voidonExit(130)
return onExit: (code: number) => voidonExit(const getErrorExitCode: (
u: unknown
) => number
Reads the runtime exit-code marker from an unknown error value.
When to use
Use to read a custom failure exit code from an unknown error value, falling
back to the default failure code.
Details
Returns the numeric [Runtime.errorExitCode] property when it is present on
an object. Otherwise returns 1, the default failure exit code used by
defaultTeardown.
Gotchas
Non-object values, missing markers, and non-number marker values all return
1.
getErrorExitCode(import CauseCause.squash(exit: Exit.Exit<E, A>(parameter) exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
exit.cause)))
}