fix: require pinHeader pinCount to be a positive integer (#756) - #783
Open
adityaaa-IIT-BHU wants to merge 1 commit into
Open
fix: require pinHeader pinCount to be a positive integer (#756)#783adityaaa-IIT-BHU wants to merge 1 commit into
adityaaa-IIT-BHU wants to merge 1 commit into
Conversation
pinCount was a bare z.number(), so fractional, zero, negative and infinite values all parsed. A fractional count is the worst of these: it produces a header whose port count and pad count disagree (pinCount=2.5 gives 2 ports but 3 pads) and nothing reports it. Zero and negative counts failed too, but later and less clearly, as pcb_missing_footprint_error — which points at the footprint when the mistake was the pin count. A count of physical pins is inherently a positive integer. Use z.number().int().positive(), the idiom already used for sampleCount and samplesPerInterval in analogacsweepsimulation.ts, with messages that name the prop. Whole counts parse to the same value as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #756
Problem
pinHeaderProps.pinCountwas a barez.number(), so fractional, zero, negative and infinite values all parsed successfully.The fractional case is the damaging one — it produces a header whose port count and pad count disagree, with no error:
pinCountsource_portsEvery whole number agrees; every fractional one leaves a pad with no port behind it, and it renders and exports without complaint.
Zero and negative counts failed too, but later and less clearly:
pcb_missing_footprint_errorpoints at the footprint. The mistake was the pin count.At the schema level, before this change:
(
NaNwas already rejected — zod'sz.number()excludes it but notInfinity.)Change
A count of physical pins is inherently a positive integer, but nothing said so. This uses the idiom already present in the repo —
analogacsweepsimulation.tsusesz.number().int().positive()forsampleCountandsamplesPerInterval— with messages that name the prop:.int()coversInfinityas well, sinceNumber.isInteger(Infinity)isfalse.Compatibility
Valid counts keep parsing to the same value, so no real header changes behaviour. The four newly-rejected inputs were all already broken downstream — either as a mismatched pad/port count or as a misleading
pcb_missing_footprint_error— so this converts silent or misattributed failures into a parse-time error naming the prop.Generated docs were refreshed per AGENTS.md; the only diff is the
pinCountblock inCOMPONENT_TYPES.md.Verification
bun test— 416 pass / 0 fail (was 412; +4 new tests intests/pin-header.test.ts)bunx tsc --noEmit— cleanbun run format:check— cleangit diff --check— clean