Skip to content

fix: resolve 4 bugs in termui - #3695

Closed
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-56120
Closed

fix: resolve 4 bugs in termui#3695
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-56120

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Filled empty catch block: silently swallowing the error hides failures; now logs for debugging.
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.

Type of Change

  • Bug fix (non-breaking change fixing an issue)

How Has This Been Tested?

  • Local manual testing

Checklist

  • My code follows the style guidelines
  • I have performed a self-review

Related Issue

Ref: #3694

Summary by CodeRabbit

  • Bug Fixes
    • Improved progress-bar percentage displays in the Pomodoro Timer and Todo App, preventing inaccurate values caused by floating-point rounding.
    • Improved error reporting for failed reload and form operations, making unexpected failures easier to diagnose.
  • Reliability
    • Added additional handling for asynchronous operation failures to reduce silently ignored errors.

@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:examples Example apps. area:ui @termuijs/ui area:dev-server @termuijs/dev-server labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates progress percentage rounding in the Pomodoro and todo examples. It also adds promise rejection logging in Form.ts and the development server reload flow.

Changes

Behavior updates

Layer / File(s) Summary
Percentage rounding corrections
examples/pomodoro-timer/src/index.tsx, examples/todo-app/src/index.ts
Both progress percentage labels add Number.EPSILON before rounding.
Promise rejection logging
packages/ui/src/Form.ts, packages/dev-server/src/server.ts
Form.ts logs rejected Promise.all operations. The development server attempts to log exitedPromise errors, but the new catch callback syntax is invalid.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fixes, but it omits the required package and GSSoC sections and does not use the required Closes # issue format. Add the affected package(s), change the issue reference to Closes #3694``, and complete the required GSSoC and checklist sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required fix: short description format and clearly identifies the four bug fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.6)
packages/dev-server/src/server.ts

File contains syntax errors that prevent linting: Line 383: Expected a parenthesis '(' but instead found '=>'.

packages/ui/src/Form.ts

File contains syntax errors that prevent linting: Line 142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/pomodoro-timer/src/index.tsx`:
- Line 185: Update both percentage renderers in
examples/pomodoro-timer/src/index.tsx:185-185 and
examples/todo-app/src/index.ts:107-107 to add Number.EPSILON to the value before
multiplying by 100, preserving the existing conditional label behavior. Add or
update tests covering 0.145 so it renders as 15% in both renderers.

In `@packages/ui/src/Form.ts`:
- Around line 141-142: Fix the malformed Promise rejection handlers in both
sites: in packages/ui/src/Form.ts lines 141-142, attach a valid callback to
Promise.all that logs the error and rethrows it, then reset validation state in
finally; in packages/dev-server/src/server.ts line 383, replace the invalid
handler with a valid (err: unknown) callback that logs the child-process exit
failure.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8df3b6dd-802b-4cb4-83b9-ed93bf721b8a

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 57e43fe.

📒 Files selected for processing (4)
  • examples/pomodoro-timer/src/index.tsx
  • examples/todo-app/src/index.ts
  • packages/dev-server/src/server.ts
  • packages/ui/src/Form.ts

const attrs = styleToCellAttrs(this._style);

const label = this._showLabel ? ` ${Math.round(this._value * 100)}%` : '';
const label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

node <<'NODE'
const value = 0.145;
const current = Math.round(value * 100 + Number.EPSILON);
const corrected = Math.round((value + Number.EPSILON) * 100);

if (current !== 14 || corrected !== 15) {
  throw new Error(`Unexpected result: current=${current}, corrected=${corrected}`);
}
NODE

Repository: Karanjot786/TermUI

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Locate changed/mentioned files:"
git ls-files | rg '(examples/pomodoro-timer/src/index\.tsx|examples/todo-app/src/index\.ts)$' || true

echo
echo "Relevant lines:"
sed -n '175,190p' examples/pomodoro-timer/src/index.tsx
echo "---"
sed -n '95,115p' examples/todo-app/src/index.ts

echo
echo "Behavioral probe for representative float boundaries:"
node <<'JS'
const boundaries = [
  0.145,
  0.00005,
  0.0145,
  0.00045,
];
for (const value of boundaries) {
  const current = Math.round(value * 100 + Number.EPSILON);
  const corrected = Math.round((value + Number.EPSILON) * 100);
  console.log(JSON.stringify({ value, current, corrected }));
}
JS

Repository: Karanjot786/TermUI

Length of output: 2017


Apply epsilon before scaling in both renderers.

Number.EPSILON is too small at the scaled value to fix values like 0.145, which currently rounds to 14%; Math.round((value + Number.EPSILON) * 100) rounds it to 15%. Update both percentage renders and add a test for 0.145.

📍 Affects 2 files
  • examples/pomodoro-timer/src/index.tsx#L185-L185 (this comment)
  • examples/todo-app/src/index.ts#L107-L107
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/pomodoro-timer/src/index.tsx` at line 185, Update both percentage
renderers in examples/pomodoro-timer/src/index.tsx:185-185 and
examples/todo-app/src/index.ts:107-107 to add Number.EPSILON to the value before
multiplying by 100, preserving the existing conditional label behavior. Add or
update tests covering 0.145 so it renders as 15% in both renderers.

Comment thread packages/ui/src/Form.ts
Comment on lines +141 to +142

.catch(err => console.error("Promise.all failed:", err)); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Correct both malformed Promise rejection handlers before merging.

Both changes contain invalid TypeScript catch syntax, so the affected files cannot compile.

  • packages/ui/src/Form.ts#L141-L142: attach the handler to Promise.all, rethrow after logging, and reset validation state in finally.
  • packages/dev-server/src/server.ts#L383-L383: use a valid callback such as (err: unknown) => console.error('Child process exit failed:', err).
🧰 Tools
🪛 Biome (2.5.6)

[error] 142-142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.

(parse)

📍 Affects 2 files
  • packages/ui/src/Form.ts#L141-L142 (this comment)
  • packages/dev-server/src/server.ts#L383-L383
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/Form.ts` around lines 141 - 142, Fix the malformed Promise
rejection handlers in both sites: in packages/ui/src/Form.ts lines 141-142,
attach a valid callback to Promise.all that logs the error and rethrows it, then
reset validation state in finally; in packages/dev-server/src/server.ts line
383, replace the invalid handler with a valid (err: unknown) callback that logs
the child-process exit failure.

Source: Linters/SAST tools

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

Labels

area:dev-server @termuijs/dev-server area:examples Example apps. area:ui @termuijs/ui type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant