Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More readable errors that use selectors instead of ids #11

Merged
merged 6 commits into from
Jul 28, 2024
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
9 changes: 4 additions & 5 deletions lib/check-each-pcb-port-connected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ function checkEachPcbPortConnected(soup: AnySoupElement[]): PCBTraceError[] {
trace.connected_source_port_ids?.includes(port.source_port_id),
)

if (
connectedTraces.length === 0 &&
sourceTrace &&
sourceTrace.connected_source_port_ids?.length > 0
) {
const hasSourceTraceWithConnections =
sourceTrace && sourceTrace.connected_source_port_ids?.length > 0

if (connectedTraces.length === 0 && hasSourceTraceWithConnections) {
errors.push({
type: "pcb_error",
message: `pcb_trace_error: PCB port ${getReadableNameForPcbPort(soup, port.pcb_port_id)} is not connected by a PCB trace`,
Expand Down
54 changes: 15 additions & 39 deletions package-lock.json

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

80 changes: 65 additions & 15 deletions tests/lib/check-each-pcb-port-connected.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("checkEachPcbPortConnected", () => {
expect(checkEachPcbPortConnected(soup)).toEqual([])
})

test("should return error when a port is not connected", () => {
test.only("should return error when a port is not connected", () => {
const soup: AnySoupElement[] = [
{
type: "pcb_port",
Expand All @@ -106,23 +106,73 @@ describe("checkEachPcbPortConnected", () => {
layers: ["top"],
},
{
type: "pcb_trace",
pcb_trace_id: "trace1",
route: [
{
x: 0,
y: 0,
width: 1,
layer: "top",
route_type: "wire",
start_pcb_port_id: "port1",
end_pcb_port_id: "somewhere",
},
],
type: "source_port",
name: "source1",
source_port_id: "source1",
source_component_id: "comp1",
pin_number: 1,
port_hints: ["1"],
},
{
type: "source_port",
name: "source2",
source_port_id: "source2",
source_component_id: "comp2",
pin_number: 2,
port_hints: ["2"],
},
{
type: "source_trace",
source_trace_id: "trace1",
connected_source_port_ids: ["source1", "source2"],
connected_source_net_ids: [],
},
{
type: "source_component",
ftype: "simple_resistor",
source_component_id: "comp1",
resistance: 1000,
name: "comp1",
supplier_part_numbers: {},
},
{
type: "source_component",
ftype: "simple_resistor",
source_component_id: "comp2",
resistance: 1000,
name: "comp2",
supplier_part_numbers: {},
},
{
type: "pcb_component",
source_component_id: "comp1",
pcb_component_id: "pcb1",
width: 1,
height: 1,
rotation: 0,
layer: "top",
center: {
x: 0,
y: 0,
},
},
{
type: "pcb_component",
source_component_id: "comp2",
pcb_component_id: "pcb2",
width: 1,
height: 1,
rotation: 0,
layer: "top",
center: {
x: 0,
y: 0,
},
},
]
const errors = checkEachPcbPortConnected(soup)
expect(errors).toHaveLength(1)
expect(errors.map((e) => e.message).join("\n")).toContain(".comp1 > .1")
expect(errors).toHaveLength(2)
})

test("should return errors for ports not connected by PCB traces", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe("checkEachPcbTraceNonOverlapping", () => {
]
const errors = checkEachPcbTraceNonOverlapping(soup)
expect(errors).toHaveLength(1)
expect(errors[0].message).toContain("overlaps with pcb_smtpad")
expect(errors[0].message).toContain("overlaps with")
expect(errors[0].pcb_trace_id).toBe("trace1")
})
})
Loading