errctx
v0.1.2
Published
Go-style error context tracking for Node.js.
Readme
errctx
Go-style error context tracking for Node.js.
Install
npm i errctxUsage
import { errgroup, errorContext } from "errctx";
import { background } from "go-like-ctx";
const ctx = background();
const ectx = errorContext(ctx);
const g = errgroup(ectx.ctx, {
onError: (err) => ectx.fail(err),
});
g.go(async (groupCtx) => {
void groupCtx;
// do work
});
await g.wait();
if (ectx.isFailed()) {
console.error("reason:", ectx.error());
}API
errorContext(ctx)
Returns an object with:
ctx: the input contextfail(err): record only the first errorerror(): returns the recorded error or nullisFailed(): true only iffail()was called
errgroup(ctx, opts)
Re-exported from the errgroup package.
Examples
examples/signup.jsexamples/signup.no-lib.js
