Skip to content

config: ignore non-positive pollMs in LoadTUIConfig - #402

Open
Kiddo4993 wants to merge 1 commit into
solongate:mainfrom
Kiddo4993:fix/issue-315
Open

Kiddo4993 wants to merge 1 commit into
solongate:mainfrom
Kiddo4993:fix/issue-315

Conversation

@Kiddo4993

Copy link
Copy Markdown

Fixes #315.

LoadTUIConfig copied any stored pollMs value into cfg.PollMs without checking it. If tui-config.json was hand-edited or corrupted to hold 0 or a negative number, that value went straight to callers. A caller using it as a polling interval would then either busy-loop or never poll.

Change: the stored value is now used only when it is greater than zero. Otherwise cfg.PollMs stays at its default, the unset zero value, the same as when pollMs is missing from the file. There is no separate default poll interval constant in the codebase. The unset zero value is the existing default, and TestLoadTUIConfigMissingFileReturnsDefault already checks for it.

I chose to fall back to the default rather than return an error, as the issue asks. This also fits LoadTUIConfig's current signature: it returns no error, and it already falls back to defaults when the file is missing or the JSON is invalid.

Tests: added TestLoadTUIConfigPollMsValidation, which covers the boundary values:

  • 0 falls back to the default
  • -1 falls back to the default
  • 1, the smallest valid value, is kept

I couldn't run the tests in this environment.

Fixes #315


Happy to adjust anything or close it if it isn't a fit.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · 3 duplication

Metric Results
Complexity 6
Duplication 3

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

✅ No blocking issues noticed

No blocking findings were identified.

Test suggestions

  • A zero pollMs value falls back to the default zero value.
  • A negative pollMs value falls back to the default zero value.
  • The smallest positive pollMs value is preserved.
  • A missing pollMs value retains the default zero value.

TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: LoadTUIConfig accepts a negative or zero PollMs with no validation

1 participant