Skip to content
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/web/src/validation/config/lora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const LoRaValidationSchema = z.object({
channelNum: z.coerce.number().int(),
overrideDutyCycle: z.boolean(),
sx126xRxBoostedGain: z.boolean(),
overrideFrequency: z.coerce.number().int(),
overrideFrequency: z.coerce.number().min(410).max(930).refine(val => Number(val.toFixed(3)) === val),
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

The decimal precision validation logic is flawed. Number(val.toFixed(3)) === val will fail for valid 3-decimal numbers due to floating-point precision issues. For example, 410.001 may not equal Number((410.001).toFixed(3)) due to IEEE 754 representation. Consider using Math.round(val * 1000) === val * 1000 instead.

Suggested change
overrideFrequency: z.coerce.number().min(410).max(930).refine(val => Number(val.toFixed(3)) === val),
overrideFrequency: z.coerce.number().min(410).max(930).refine(val => Math.round(val * 1000) === val * 1000),

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The AI was correct (for once), 410.001 failed and provided 410.0010070800781 on reboot.
However, the provided fix doesn't work and I tried several other methods.

Would a frequency slot validation function be appropriate?
Otherwise, valid inputs seem to work fine without rounding errors.

Copy link
Contributor

@philon- philon- Aug 22, 2025

Choose a reason for hiding this comment

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

If you want you can add a more descriptive error message than "Invalid Input" by passing
{ message: "formValidation.maxSigFig", params: { sigFigs: 3 } }
to refine() and add the translation key to packages/web/public/i18n/locales/en/common.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, although I wasn't sure how to make it parameterised for the frequency.

ignoreIncoming: z.coerce.number().array(),
ignoreMqtt: z.boolean(),
configOkToMqtt: z.boolean(),
Expand Down