Skip to content

feat(util): add validateResultNumber helper - #874

Open
danwilliams-cll wants to merge 2 commits into
mainfrom
feat/util-validate-result-number
Open

feat(util): add validateResultNumber helper#874
danwilliams-cll wants to merge 2 commits into
mainfrom
feat/util-validate-result-number

Conversation

@danwilliams-cll

Copy link
Copy Markdown

Adds a reusable helper to validate numeric provider results before coercion, returning a structured 502 error for null/undefined/NaN/empty/objects/arrays/booleans/Infinity. Includes behavior-table unit tests.

Adds a shared helper to validate raw numeric provider values before Number()
coercion. Invalid values (null, undefined, NaN, empty strings, non-numeric
types, infinity) produce a 502 provider error response. 0 is accepted by
default with an opt-out flag.

Includes unit tests covering the behavior table.
@danwilliams-cll
danwilliams-cll requested a review from a team as a code owner August 13, 2026 22:23
@github-actions

Copy link
Copy Markdown
Contributor

👋 danwilliams-cll, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

NPM Publishing labels 🏷️

🔵 This PR has the none label set and it will not cause a version bump.

Comment thread src/util/result-number.ts
isWrongType || trimmed === '' || !Number.isFinite(num) || (!acceptZeroValue && num === 0)

if (isInvalid) {
logger.warn(`${errorMessage} (received: ${JSON.stringify(value)})`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should avoid stringifying in logs, should be able to pass this out as an object (`{ msg: "asd", otherprop: obj })and it will only be parsed to a string if the log level is set to it (usually a warn will do it anyways but just as a general comment

Comment thread src/util/result-number.ts
Comment on lines +21 to +26
/**
* Type guard for the error branch of ValidatedResultNumber.
*/
export const isProviderError = (
v: ValidatedResultNumber,
): v is { statusCode: 502; errorMessage: string } => 'statusCode' in v

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used for tests, should live below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants