Repository
Current version released
3 years ago
Versions
errgo
Better error handling. Inspired by error handling in golang.
Installation
Deno
import { Result, must, wrap } from "https://deno.land/x/errgo/mod.ts";Node.js
pnpm add @klapacz/errgoExample
Result
import { Result } from "https://deno.land/x/errgo/mod.ts";
async function readFile(path: string): Result<string> {
if (exists(path)) {
return [undefined, await readFile(path)];
}
return [new Error("invalid path")];
}
const [err, result] = readFile("test.txt");
if (!err) {
result; // typescript knows result is defined
}must
import { must } from "https://deno.land/x/errgo/mod.ts";
// throws error if returned by `readFile(…)`
const result = must(readFile("test.txt"));wrap
import { wrap } from "https://deno.land/x/errgo/mod.ts";
const [err, result] = await wrap(fetch("…"));
if (!err) {
result; // typescript knows result is defined
}Alternatives
Releasing
Deno
git tag VERSION_HERE
git push origin --tagsNode.js
# run script
deno run -A scripts/build_npm.ts VERSION_HERE
# go to output directory and publish
cd npm
npm publish