Skip to content

fix(utils): make getStartEndDates validation guard actually validate#643

Merged
arturasmckwcz merged 1 commit into
developfrom
fix-get-start-end-dates-validation-guard
Jun 8, 2026
Merged

fix(utils): make getStartEndDates validation guard actually validate#643
arturasmckwcz merged 1 commit into
developfrom
fix-get-start-end-dates-validation-guard

Conversation

@arturasmckwcz

Copy link
Copy Markdown
Collaborator

Surfaced while reviewing the data-utils tests in #528.

getStartEndDates's guard was unsatisfiable:

if (startHour < endHour && startHour < 0 && startHour > 24 && endHour < 0 && endHour > 24)

startHour < 0 && startHour > 24 can never both hold, so invalid hours never threw. Replaced with the intended check — throw unless 0 <= startHour < endHour <= 24.

Scope: source-only. getStartEndDates has no production callers today (only the unit test in #528), so this is a correctness/hygiene fix with no runtime behavior change for live code, and the happy-path inputs in #528 (start < end, in range) still pass. The throw-path test belongs with the suite in #528, so this PR deliberately doesn't touch the test file (avoids a conflict with #528).

Not included: getStartEnd's map has questionable entries (e.g. "17:00-20:00" → 14..17), but it has 4 real callers and some entries look like intentional slot-snapping — correcting it would change live availability parsing, so it needs domain review, not a blind fix. Flagged on #528.

🤖 Generated with Claude Code

@arturasmckwcz arturasmckwcz force-pushed the fix-get-start-end-dates-validation-guard branch from d908c7c to 28694c3 Compare June 8, 2026 11:04
@arturasmckwcz

Copy link
Copy Markdown
Collaborator Author

Updated: in addition to fixing the unsatisfiable guard, getStartEndDates now throws BadRequestError instead of a raw Error. The global error handler (src/server/index.ts) only maps BaseError subclasses to their status code; a raw Error falls through to 500. Invalid hours are a bad-request case, so this now yields 400 — per the error-handling convention in CLAUDE.md.

getStartEndDates had no production callers (referenced only by its own
definition and the barrel re-export) and its validation guard was dead code.
Rather than fix a dead function, remove it. Its sibling getStartEnd (4 callers)
stays in the same file.

Surfaced while reviewing the data-utils tests in #528 — the getStartEndDates
tests there should be dropped (keep the getStartEnd ones).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arturasmckwcz arturasmckwcz force-pushed the fix-get-start-end-dates-validation-guard branch from 28694c3 to e6e6034 Compare June 8, 2026 11:06
@arturasmckwcz

Copy link
Copy Markdown
Collaborator Author

Changed direction per review: getStartEndDates is stray (no production callers — only its own definition + the barrel re-export, no tests on develop). Rather than fix a dead function's guard, this now removes it. Its sibling getStartEnd (4 callers) stays. Source-only; typecheck green.

@need4deed need4deed left a comment

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.

Approved: remove stray getStartEndDates (no production callers); getStartEnd retained. Source-only, typecheck green.

@arturasmckwcz arturasmckwcz merged commit 55308a2 into develop Jun 8, 2026
@arturasmckwcz arturasmckwcz deleted the fix-get-start-end-dates-validation-guard branch June 8, 2026 11:08
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.

2 participants