Skip to main content
Deno 2 is finally here 🎉️
Learn more

Custom Stack

Create a fancy error with a custom stack.

// Imports
import { createError } from "https://deno.land/x/cstack@0.1.0/mod.ts";

You can create an error by either passing an error object or creating your own custom stack.

throw createError(new Error("hello world!"));

or

throw createError({
  name: "Custom Error",
  message: "hello world",
  trace: [
    { at: "somewhere" },
    { at: "file://a/b/c.ts", async: true },
    { at: "file://a/b/c.ts", y: 123 },
    { at: "file://a/b/c.ts", y: 123, x: 456 },
    "    strings work too",
  ],
});

preview

Cstack produces clean error objects, yet beautiful errors when thrown.

try {
  throw error;
} catch (error) {
  console.log("Name:", error.name);
  console.log("Message:", error.message);
  console.log("Stack:", error.stack);
}

throw error;

preview