@tscircuit/core 0.0.50 → 0.0.51

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/index.d.ts CHANGED
@@ -78,7 +78,7 @@ declare abstract class Renderable implements IRenderable {
78
78
  */
79
79
  runRenderPhase(phase: RenderPhase): void;
80
80
  runRenderPhaseForChildren(phase: RenderPhase): void;
81
- renderError(message: string | PCBTraceError | PCBPlacementError): void;
81
+ renderError(message: string | Omit<PCBTraceError, "pcb_error_id"> | Omit<PCBPlacementError, "pcb_error_id">): void;
82
82
  }
83
83
 
84
84
  interface BaseComponentConfig {
@@ -229,6 +229,7 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
229
229
  }): PrimitiveComponent | null;
230
230
  getAvailablePcbLayers(): string[];
231
231
  getDescendants(): PrimitiveComponent[];
232
+ renderError(message: Parameters<typeof Renderable.prototype.renderError>[0]): void;
232
233
  getString(): string;
233
234
  get [Symbol.toStringTag](): string;
234
235
  }
package/dist/index.js CHANGED
@@ -125,6 +125,7 @@ var Renderable = class {
125
125
  if (typeof message === "string") {
126
126
  throw new Error(message);
127
127
  }
128
+ throw new Error(JSON.stringify(message, null, 2));
128
129
  }
129
130
  };
130
131
 
@@ -487,6 +488,15 @@ var PrimitiveComponent = class extends Renderable {
487
488
  }
488
489
  return descendants;
489
490
  }
491
+ // TODO we shouldn't need to override this, errors can be rendered and handled
492
+ // by the Renderable class, however, the Renderable class currently doesn't
493
+ // have access to the database or cleanup
494
+ renderError(message) {
495
+ if (typeof message === "string") {
496
+ return super.renderError(message);
497
+ }
498
+ this.root?.db.pcb_error.insert(message);
499
+ }
490
500
  getString() {
491
501
  const { lowercaseComponentName: cname, _parsedProps: props, parent } = this;
492
502
  if (parent?.props?.name && props?.name) {
@@ -2495,9 +2505,16 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
2495
2505
  });
2496
2506
  const traces = ijump.solveAndMapToTraces();
2497
2507
  if (traces.length === 0) {
2498
- this.renderError(
2499
- `Could not find a route between ${JSON.stringify(a)} and ${JSON.stringify(b)} for ${this}`
2500
- );
2508
+ this.renderError({
2509
+ type: "pcb_error",
2510
+ error_type: "pcb_trace_error",
2511
+ message: `Could not find a route for ${this}`,
2512
+ source_trace_id: this.source_trace_id,
2513
+ center: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
2514
+ pcb_port_ids: ports.map((p) => p.pcb_port_id),
2515
+ pcb_trace_id: this.pcb_trace_id,
2516
+ pcb_component_ids: ports.map((p) => p.pcb_component_id)
2517
+ });
2501
2518
  return;
2502
2519
  }
2503
2520
  const [trace] = traces;
@@ -442,6 +442,17 @@ export abstract class PrimitiveComponent<
442
442
  return descendants
443
443
  }
444
444
 
445
+ // TODO we shouldn't need to override this, errors can be rendered and handled
446
+ // by the Renderable class, however, the Renderable class currently doesn't
447
+ // have access to the database or cleanup
448
+ renderError(message: Parameters<typeof Renderable.prototype.renderError>[0]) {
449
+ if (typeof message === "string") {
450
+ return super.renderError(message)
451
+ }
452
+ // TODO this needs to be cleaned up at some point!
453
+ this.root?.db.pcb_error.insert(message)
454
+ }
455
+
445
456
  getString(): string {
446
457
  const { lowercaseComponentName: cname, _parsedProps: props, parent } = this
447
458
  if (parent?.props?.name && props?.name) {
@@ -110,11 +110,17 @@ export abstract class Renderable implements IRenderable {
110
110
  }
111
111
  }
112
112
 
113
- renderError(message: string | PCBTraceError | PCBPlacementError) {
113
+ renderError(
114
+ message:
115
+ | string
116
+ | Omit<PCBTraceError, "pcb_error_id">
117
+ | Omit<PCBPlacementError, "pcb_error_id">,
118
+ ) {
114
119
  // TODO add to render phase error list and try to add position or
115
120
  // relationships etc.
116
121
  if (typeof message === "string") {
117
122
  throw new Error(message)
118
123
  }
124
+ throw new Error(JSON.stringify(message, null, 2))
119
125
  }
120
126
  }
@@ -439,9 +439,16 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {
439
439
  })
440
440
  const traces = ijump.solveAndMapToTraces()
441
441
  if (traces.length === 0) {
442
- this.renderError(
443
- `Could not find a route between ${JSON.stringify(a)} and ${JSON.stringify(b)} for ${this}`,
444
- )
442
+ this.renderError({
443
+ type: "pcb_error",
444
+ error_type: "pcb_trace_error",
445
+ message: `Could not find a route for ${this}`,
446
+ source_trace_id: this.source_trace_id!,
447
+ center: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
448
+ pcb_port_ids: ports.map((p) => p.pcb_port_id!),
449
+ pcb_trace_id: this.pcb_trace_id!,
450
+ pcb_component_ids: ports.map((p) => p.pcb_component_id!),
451
+ })
445
452
  return
446
453
  }
447
454
  // TODO ijump returns multiple traces for some reason
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/core",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.0.50",
5
+ "version": "0.0.51",
6
6
  "types": "dist/index.d.ts",
7
7
  "main": "dist/index.js",
8
8
  "files": [