error-mom 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +33 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { Command } from "commander";
|
|
|
10
10
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
11
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
12
12
|
import { z } from "zod";
|
|
13
|
-
var VERSION = "0.
|
|
13
|
+
var VERSION = "0.2.0";
|
|
14
14
|
var CONFIG_DIR = join(homedir(), ".error-mom");
|
|
15
15
|
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
16
16
|
var program = new Command().name("error-mom").description("Query and operate a self-hosted Error Mom incident desk").version(VERSION);
|
|
@@ -122,7 +122,7 @@ program.command("init").description("Create/select a project, install the SDK, a
|
|
|
122
122
|
framework,
|
|
123
123
|
setupFile: setupPath,
|
|
124
124
|
verified: false,
|
|
125
|
-
nextAction: `Import ${setupPath} from the earliest ${framework} entry point,
|
|
125
|
+
nextAction: framework === "next" ? `Import ${setupPath} from the root layout for client errors; instrumentation.ts already reports server errors. For jobs/handlers that catch errors themselves (queues, webhooks, MCP tools), wrap them with errorMom.wrap(fn). Then run error-mom doctor --project-key <key>.` : `Import ${setupPath} from the earliest ${framework} entry point. For code where a framework catches errors itself (job runners, webhooks, MCP tools), wrap handlers with errorMom.wrap(fn). Then run error-mom doctor --project-key <key>.`
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
program.command("mcp").description("Run Error Mom tools over MCP stdio for coding agents").action(async () => {
|
|
@@ -271,6 +271,7 @@ function installSdk(packageManager) {
|
|
|
271
271
|
async function writeSetup(framework) {
|
|
272
272
|
const sourceDirectory = existsSync(join(process.cwd(), "src")) ? "src" : ".";
|
|
273
273
|
const relativePath = join(sourceDirectory, "error-mom.ts");
|
|
274
|
+
if (framework === "next") await writeNextInstrumentation(sourceDirectory);
|
|
274
275
|
const environment = framework === "next" ? "process.env.NEXT_PUBLIC_" : framework === "vite" ? "import.meta.env.VITE_" : "process.env.";
|
|
275
276
|
const moduleName = framework === "node" ? "@kenkaiiii/error-mom/node" : "@kenkaiiii/error-mom";
|
|
276
277
|
const contents = `${framework === "next" ? '"use client";\n\n' : ""}import { initErrorMom } from "${moduleName}";
|
|
@@ -293,6 +294,35 @@ initErrorMom({
|
|
|
293
294
|
await writeFile(join(process.cwd(), relativePath), contents);
|
|
294
295
|
return relativePath;
|
|
295
296
|
}
|
|
297
|
+
async function writeNextInstrumentation(sourceDirectory) {
|
|
298
|
+
const file = join(process.cwd(), sourceDirectory, "instrumentation.ts");
|
|
299
|
+
if (existsSync(file)) return;
|
|
300
|
+
const contents = `import type { Instrumentation } from "next";
|
|
301
|
+
|
|
302
|
+
// Reports server-side errors (API routes, SSR, server actions, middleware)
|
|
303
|
+
// that Next.js catches before they can become uncaught exceptions.
|
|
304
|
+
export const onRequestError: Instrumentation.onRequestError = async (
|
|
305
|
+
error,
|
|
306
|
+
request,
|
|
307
|
+
context,
|
|
308
|
+
) => {
|
|
309
|
+
if (process.env.NEXT_RUNTIME !== "nodejs") return;
|
|
310
|
+
const server = process.env.NEXT_PUBLIC_ERROR_MOM_SERVER;
|
|
311
|
+
const projectKey = process.env.NEXT_PUBLIC_ERROR_MOM_PROJECT_KEY;
|
|
312
|
+
if (!server || !projectKey) return;
|
|
313
|
+
const { initErrorMom } = await import("@kenkaiiii/error-mom/node");
|
|
314
|
+
initErrorMom({
|
|
315
|
+
server,
|
|
316
|
+
projectKey,
|
|
317
|
+
environment: process.env.NEXT_PUBLIC_ERROR_MOM_ENVIRONMENT ?? "production",
|
|
318
|
+
}).captureError(error, {
|
|
319
|
+
culprit: \`\${request.method} \${request.path}\`,
|
|
320
|
+
tags: { routerKind: context.routerKind, routeType: context.routeType, runtime: "server" },
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
`;
|
|
324
|
+
await writeFile(file, contents);
|
|
325
|
+
}
|
|
296
326
|
async function appendEnvironment(framework, server, key) {
|
|
297
327
|
const prefix = framework === "next" ? "NEXT_PUBLIC_" : framework === "vite" ? "VITE_" : "";
|
|
298
328
|
const file = join(process.cwd(), ".env.local");
|
|
@@ -321,7 +351,7 @@ function syntheticEvent() {
|
|
|
321
351
|
error: {
|
|
322
352
|
name: "ErrorMomDoctor",
|
|
323
353
|
message: "Synthetic setup verification",
|
|
324
|
-
stack: "ErrorMomDoctor: Synthetic setup verification
|
|
354
|
+
stack: "ErrorMomDoctor: Synthetic setup verification\n at error-mom doctor:1:1"
|
|
325
355
|
},
|
|
326
356
|
environment: "setup",
|
|
327
357
|
release: VERSION,
|