Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/error-sink/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ export function reportError(
}

export type { ErrorContext } from "./context";
export { generateRefId } from "./ref-id";
14 changes: 14 additions & 0 deletions packages/error-sink/src/ref-id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, test } from "bun:test";
import { generateRefId } from "./ref-id";

describe("generateRefId", () => {
test("produces a non-empty string", () => {
const refId = generateRefId();
expect(typeof refId).toBe("string");
expect(refId.length).toBeGreaterThan(0);
});

test("is not constant across calls", () => {
expect(generateRefId()).not.toBe(generateRefId());
});
});
11 changes: 6 additions & 5 deletions packages/error-sink/src/ref-id.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Mints the same short, quotable, grep-able shape `@workbench/hub-client`'s
// `generateRefId` does, without depending on that package: hub-client
// pulls in the full workflow-catalog and inference stack, which this
// package's browser callers (and its own server-side ones) have no
// reason to carry just to mint an id.
// The sole implementation of the short, quotable, grep-able refId shape
// (CL-7253). `@workbench/hub-client` re-exports this rather than keeping
// its own copy; this package stays free of `@workbench/hub-client`'s
// workflow-catalog and inference stack, which this package's browser
// callers (and its own server-side ones) have no reason to carry just to
// mint an id.
export function generateRefId(): string {
const random = Math.random().toString(36).slice(2, 8);
return `${Date.now().toString(36)}-${random}`;
Expand Down
1 change: 1 addition & 0 deletions packages/hub-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@corbits/assistant-workflow": "workspace:*",
"@corbits/echo-workflow": "workspace:*",
"@corbits/error-sink": "workspace:*",
"@corbits/heartbeat-workflow": "workspace:*",
"@corbits/inference-catalog": "workspace:*",
"@corbits/last-30-days-research-workflow": "workspace:*",
Expand Down
10 changes: 1 addition & 9 deletions packages/hub-client/src/error-envelope.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { describe, expect, test } from "bun:test";
import {
generateRefId,
makeErrorEnvelope,
parseErrorEnvelope,
} from "./error-envelope";
import { makeErrorEnvelope, parseErrorEnvelope } from "./error-envelope";

describe("error envelope", () => {
test("makeErrorEnvelope carries code, userMessage, and a generated refId", () => {
Expand All @@ -19,10 +15,6 @@ describe("error envelope", () => {
expect(envelope.error.refId.length).toBeGreaterThan(0);
});

test("refIds are not constant across calls", () => {
expect(generateRefId()).not.toBe(generateRefId());
});

test("parseErrorEnvelope accepts a well-formed envelope", () => {
const body = {
error: { code: "x", userMessage: "y", refId: "z" },
Expand Down
11 changes: 3 additions & 8 deletions packages/hub-client/src/error-envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
// hub's own logger, keyed by the same `refId`, so an operator can find
// it without the client ever having seen it. See CL-6360.

import { generateRefId } from "@corbits/error-sink";
import { type } from "arktype";

export { generateRefId };

export const ErrorEnvelopeShape = type({
error: {
code: "string",
Expand All @@ -18,14 +21,6 @@ export const ErrorEnvelopeShape = type({

export type ErrorEnvelope = typeof ErrorEnvelopeShape.infer;

/** Short enough to read aloud, unique enough to grep a log for. Never a
* secret and never derived from anything sensitive — it is a lookup key,
* not a token. */
export function generateRefId(): string {
const random = Math.random().toString(36).slice(2, 8);
return `${Date.now().toString(36)}-${random}`;
}

export function makeErrorEnvelope(args: {
code: string;
userMessage: string;
Expand Down
Loading