Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(onshape): tighten the panel diagnostics report

Raul4d1049e8ac06
diff --git a/.claude/rules/onshape-panel.md b/.claude/rules/onshape-panel.md
index 94796f0c7f..b5ab540715 100644
--- a/.claude/rules/onshape-panel.md
+++ b/.claude/rules/onshape-panel.md
@@ -142,7 +142,7 @@ The gateway rejects a request line over 4,096 bytes, and a PostgREST `.in()` lis
## Panel UI
- Pages: the push page (labelled Parts, Assembly, or Push on any other element, where it says there is nothing to push), Releases (needs a `documentId`) and Fields (settings update, on a Part Studio or assembly). The Carbon company and Sign out sit on the right.
-- Errors carry `diagnostics`, shown by `PanelDiagnostics` behind Show details / Copy details together with the panel's own URL parameters and the Carbon host. Sources: every `onshapeFailure` body (`OnshapeFailureDiagnostics`: the read, Onshape's status, the `message` of its error body via `OnshapeApiError.onshapeMessage`, or the transport error when nothing answered; never the raw body), and the missing-columns refusals of `status`, `plan-assembly` and `plan-release` (the request coordinates, `onshapeApi` from `OnshapeClient.apiOrigin`, the missing columns, `describeBomPayload`: payload keys, header ids, names and property names, row count, template id; never a cell value). `plan-release` returns them per unread BOM beside its warnings, and each route logs the same at warn.
+- Errors carry `diagnostics`, shown by `PanelDiagnostics` behind Show details / Copy details together with the Carbon host and the panel's own URL parameters (only `REPORTED_PANEL_PARAMS`: the action-URL placeholders plus `server`, raw so an unfilled `{$elementId}` shows; any other parameter is dropped). The report is rebuilt when the diagnostics change. Sources: every `onshapeFailure` body (`OnshapeFailureDiagnostics`: the read, `onshapeApi` from `OnshapeApiError.apiOrigin`, Onshape's status, the `message` of its error body via `OnshapeApiError.onshapeMessage`, or the transport error when nothing answered; never the raw body), and the missing-columns refusals of `status`, `plan-assembly` and `plan-release` (the request coordinates, `onshapeApi` from `OnshapeClient.apiOrigin`, the missing columns, `describeBomPayload`: payload keys, header ids, names and property names, row count, template id; never a cell value). `plan-release` returns them per unread BOM beside its warnings, and each route logs the same at warn.
- The theme follows Onshape's `theme` action-URL parameter: the `onshape+` layout declares `handle.hostMode` and the root renders that mode. Missing means light.
- Part badges: Linked, Conflict (same part number, not linked to this source; a push uses that item), Unlinked, and Released (released in Onshape; its Push is disabled because changes come through a release). Release states: In Carbon, Partial, Not in Carbon. The assembly BOM is the structured tree (`panel/bom-view.ts`).
- Moving to another element clears a part or assembly review and the Fields state; a release review survives within the same document.
diff --git a/docs/content/docs/integrations/cad.mdx b/docs/content/docs/integrations/cad.mdx
index b7aa4f89c2..f37ce41585 100644
--- a/docs/content/docs/integrations/cad.mdx
+++ b/docs/content/docs/integrations/cad.mdx
@@ -392,10 +392,12 @@ the push defaults together.
## Troubleshooting the panel
-Every error in the panel has **Show details** and **Copy details**: what Carbon
-asked Onshape and what Onshape answered, including its status and message, and
-for a BOM that can't be read, the column headers Onshape returned. Paste it into
-a support request. It never contains a token or a cell value.
+When the panel can't read from Onshape, or an assembly's BOM is missing a column
+the panel needs, the error has **Show details** and **Copy details**: what
+Carbon asked Onshape and what Onshape answered, including the Onshape address,
+its status and message, and for a BOM that can't be read, the column headers
+Onshape returned. Paste it into a support request. It never contains a token or
+a cell value.
| Symptom | Cause | Fix |
| --- | --- | --- |
diff --git a/packages/ee/src/onshape/lib/client.ts b/packages/ee/src/onshape/lib/client.ts
index 09a666e8e1..129f586ad5 100644
--- a/packages/ee/src/onshape/lib/client.ts
+++ b/packages/ee/src/onshape/lib/client.ts
@@ -179,18 +179,22 @@ export class OnshapeApiError extends Error {
retryAfterSeconds?: number;
/** The `message` of Onshape's error body, when it sent one. */
onshapeMessage?: string;
+ /** The Onshape origin the failed call went to. */
+ apiOrigin?: string;
constructor(
message: string,
status?: number,
retryAfterSeconds?: number,
- onshapeMessage?: string
+ onshapeMessage?: string,
+ apiOrigin?: string
) {
super(message);
this.name = "OnshapeApiError";
this.status = status;
this.retryAfterSeconds = retryAfterSeconds;
this.onshapeMessage = onshapeMessage;
+ this.apiOrigin = apiOrigin;
}
}
@@ -348,7 +352,13 @@ export class OnshapeClient {
// own message (e.g. "timeout of 60000ms exceeded") instead of the useless
// "Onshape API error (undefined): undefined".
if (status === undefined) {
- return new OnshapeApiError(`Onshape request failed: ${error.message}`);
+ return new OnshapeApiError(
+ `Onshape request failed: ${error.message}`,
+ undefined,
+ undefined,
+ undefined,
+ this.baseUrl
+ );
}
const parsedRetryAfter = Number(error.response?.headers?.["retry-after"]);
const data = error.response?.data as unknown;
@@ -362,7 +372,8 @@ export class OnshapeClient {
}`,
status,
Number.isFinite(parsedRetryAfter) ? parsedRetryAfter : undefined,
- typeof onshapeMessage === "string" ? onshapeMessage : undefined
+ typeof onshapeMessage === "string" ? onshapeMessage : undefined,
+ this.baseUrl
);
}
return error instanceof Error ? error : new Error(String(error));
diff --git a/packages/ee/src/onshape/lib/onshape-failure.test.ts b/packages/ee/src/onshape/lib/onshape-failure.test.ts
index 802748daf1..7012d25ece 100644
--- a/packages/ee/src/onshape/lib/onshape-failure.test.ts
+++ b/packages/ee/src/onshape/lib/onshape-failure.test.ts
@@ -11,7 +11,8 @@ class OnshapeApiError extends Error {
message: string,
public status?: number,
public retryAfterSeconds?: number,
- public onshapeMessage?: string
+ public onshapeMessage?: string,
+ public apiOrigin?: string
) {
super(message);
}
@@ -94,12 +95,14 @@ describe("onshapeFailure", () => {
'Onshape API error (403): {"message":"Access denied","stack":"secret"}',
403,
undefined,
- "Access denied"
+ "Access denied",
+ "https://cad.onshape.com"
),
"bom"
);
expect(failure.body.diagnostics).toEqual({
read: "bom",
+ onshapeApi: "https://cad.onshape.com",
onshapeStatus: 403,
onshapeMessage: "Access denied",
transport: null
@@ -115,6 +118,12 @@ describe("onshapeFailure", () => {
});
});
+ it("leaves the origin empty when the throw did not come from the client", () => {
+ expect(onshapeFailure(new Error("boom")).body.diagnostics.onshapeApi).toBe(
+ null
+ );
+ });
+
it("handles a non-Onshape throw", () => {
expect(onshapeFailure(new Error("boom")).status).toBe(502);
expect(onshapeFailure("not an error").status).toBe(502);
diff --git a/packages/ee/src/onshape/lib/onshape-failure.ts b/packages/ee/src/onshape/lib/onshape-failure.ts
index 7cf57aff39..ec282b8784 100644
--- a/packages/ee/src/onshape/lib/onshape-failure.ts
+++ b/packages/ee/src/onshape/lib/onshape-failure.ts
@@ -30,6 +30,8 @@ export type OnshapeRead = "bom" | "other";
*/
export type OnshapeFailureDiagnostics = {
read: OnshapeRead;
+ /** The Onshape origin Carbon called, from `OnshapeApiError.apiOrigin`. */
+ onshapeApi: string | null;
onshapeStatus: number | null;
onshapeMessage: string | null;
/** No response at all: the client's own description (timeout, network). */
@@ -47,6 +49,8 @@ export function onshapeFailure(
const message = error instanceof Error ? error.message : String(error);
const diagnostics: OnshapeFailureDiagnostics = {
read,
+ onshapeApi:
+ typeof apiError?.apiOrigin === "string" ? apiError.apiOrigin : null,
onshapeStatus: status ?? null,
onshapeMessage:
typeof apiError?.onshapeMessage === "string"
diff --git a/packages/ee/src/onshape/panel/Panel.tsx b/packages/ee/src/onshape/panel/Panel.tsx
index e5f8f61197..6b5d374d68 100644
--- a/packages/ee/src/onshape/panel/Panel.tsx
+++ b/packages/ee/src/onshape/panel/Panel.tsx
@@ -691,31 +691,70 @@ async function copyText(text: string): Promise<boolean> {
}
}
+/**
+ * The panel URL parameters a report carries: the ones the action URL asks
+ * Onshape to fill, plus `server`. Raw values, so an unfilled `{$elementId}`
+ * shows; any other parameter is left out.
+ */
+const REPORTED_PANEL_PARAMS = [
+ "documentId",
+ "wv",
+ "wvId",
+ "elementId",
+ "partNumber",
+ "revision",
+ "nodeId",
+ "occurrencePath",
+ "configuration",
+ "companyId",
+ "userId",
+ "locale",
+ "clientId",
+ "server"
+] as const satisfies readonly (keyof OnshapePanelContext | "server")[];
+
+function reportedPanelParams(search: string): Record<string, string> {
+ const params = new URLSearchParams(search);
+ const reported: Record<string, string> = {};
+ for (const name of REPORTED_PANEL_PARAMS) {
+ const value = params.get(name);
+ if (value !== null) reported[name] = value;
+ }
+ return reported;
+}
+
/**
* What Carbon asked Onshape and what it answered, plus the panel's own URL
* parameters, so a failure can be reported as it happened. Never a token.
*/
function PanelDiagnostics({ diagnostics }: { diagnostics: unknown }) {
const [open, setOpen] = useState(false);
- const [copied, setCopied] = useState(false);
- const [report] = useState(() =>
- JSON.stringify(
- {
- capturedAt: datetime.timestamp(),
- carbonHost: typeof window === "undefined" ? null : window.location.host,
- panel:
- typeof window === "undefined"
- ? {}
- : Object.fromEntries(new URLSearchParams(window.location.search)),
- details: diagnostics
- },
- null,
- 2
- )
+ // The report last copied: a new review's diagnostics read "Copy details" again.
+ const [copiedReport, setCopiedReport] = useState<string | null>(null);
+ // Keyed on content, so a re-render with equal diagnostics keeps capturedAt.
+ const details = JSON.stringify(diagnostics ?? null);
+ const report = useMemo(
+ () =>
+ JSON.stringify(
+ {
+ capturedAt: datetime.timestamp(),
+ carbonHost:
+ typeof window === "undefined" ? null : window.location.host,
+ panel:
+ typeof window === "undefined"
+ ? {}
+ : reportedPanelParams(window.location.search),
+ details: JSON.parse(details) as unknown
+ },
+ null,
+ 2
+ ),
+ [details]
);
+ const copied = copiedReport === report;
const copy = async () => {
if (await copyText(report)) {
- setCopied(true);
+ setCopiedReport(report);
} else {
// Nothing could write the clipboard: show the text to select instead.
setOpen(true);