Handling Errors
In real apps, things go wrong. A network request might fail, a data transformation might error out, or an external service might be unavailable. When this happens, App-Compose isolates the failure so the rest of your app continues to work as expected.
Task errors only come from run.fn or enabled.fn.
Failure behavior
Section titled “Failure behavior”If a Task fails, App-Compose marks it as failed and keeps the app running. Any Task that strictly depends on it, directly or through Tags, is marked as skipped.
import { status } from "@grlt-hub/app-compose"
const alpha = createTask({ name: "alpha", run: { fn: () => { throw new Error("Oops!") }, },})
const beta = createTask({ name: "alpha", run: { fn: () => {}, context: { alpha }, },})
const gamma = createTask({ name: "gamma", run: { fn: (ctx) => { ctx.forEach((x) => console.log(x)) }, context: [ { "alpha.status.name": status(alpha).name, }, { "beta.status.name": status(beta).name }, ], },})
compose({}).stage([alpha]).stage([beta]).stage([gamma]).run()Logging Failures
Section titled “Logging Failures”By default, App-Compose logs a warning to the console when a Task fails. You can customize this behavior with the onTaskFail. This is useful for separating dev and production handling, for example sending errors to a logging system like Sentry.
const alpha = createTask({ name: "alpha", run: { fn: () => { throw new Error("Oops!") }, },})
const onTaskFail = (task) => { console.log(`*** ERROR *** \n ${String(task.id)} :: ${task.error}`)}
compose({ // 👇 Handle task failures here log: { onTaskFail },}) .stage([alpha]) .run()