tscircuit / tscircuit/core

pinheader emits string pins in schematic port_arrangement, failing circuit-json's parser

Open Beginner friendly
#3,075 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
58
Forks
203
Avg merge
7h 39m
Merged PRs (30d)
286

Description

A <pinheader> makes the board's circuit-json fail circuit-json's own parser (any_circuit_element).

What happens

Building a board with a <pinheader> produces a schematic_component that fails circuit-json's own parser. Both any_circuit_element.safeParse(...) and schematic_component.safeParse(...) return success: false for that element, so the board's circuit-json no longer validates against the schema it is meant to match. Pin headers are a common part, so this affects a lot of boards.

Repro

import { any_circuit_element } from "circuit-json"

circuit.add(
  <board width="20mm" height="20mm">
    <pinheader name="J1" pinCount={2} footprint="pinrow2" />
  </board>,
)
await circuit.renderUntilSettled()

const sc = circuit
  .getCircuitJson()
  .find((e) => e.type === "schematic_component")

// sc.port_arrangement.right_side.pins === ["pin1", "pin2"]
any_circuit_element.safeParse(sc).success // false

Cause

The emitted schematic_component.port_arrangement.<side>.pins is an array of label strings ["pin1", "pin2", ...], but circuit-json's schematic_component_port_arrangement_by_sides schema requires pin numbers:

left_side: z.object({ pins: z.array(z.number()), /* ... */ }).optional()

so the string pins fail validation. Chips emit port_arrangement: undefined and parse fine, so this is specific to the pin header building string pins.

Environment

  • @tscircuit/core at HEAD fe733758
  • circuit-json 0.0.464

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pinheader schematic_component generation reached by circuit.add and circuit.getCircuitJson(), then run the provided reproduction with any_circuit_element.safeParse and schematic_component.safeParse. Trace the port_arrangement output and add or update coverage so a two-pin header produces circuit-json that both schemas accept.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.