Skip to content

Improve type safety and fallback logic in isDutyLeaveConstraintError#347

Merged
devakesu merged 2 commits into1.5.3from
copilot/sub-pr-346
Feb 12, 2026
Merged

Improve type safety and fallback logic in isDutyLeaveConstraintError#347
devakesu merged 2 commits into1.5.3from
copilot/sub-pr-346

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

Addresses review feedback on duty-leave constraint error detection: parameter type collapsed to any, and nested details check prevented message fallback.

Type Safety

  • Parameter changed from DatabaseError | any | null | undefined to unknown
  • Added runtime type narrowing with typeof checks and explicit casting

Nested Error Detection

  • details property now validated as object before accessing nested fields
  • Removed early return to allow message fallback when details is non-object (e.g., string)

Before:

if (error.details) {
  return (
    error.details.code === "P0001" &&
    error.details.hint === "..."
  );
}
// Message fallback unreachable if details is truthy

After:

if (errorObj.details && typeof errorObj.details === "object") {
  const details = errorObj.details as Record<string, unknown>;
  const isNestedMatch = details.code === "P0001" && details.hint === "...";
  if (isNestedMatch) {
    return true;
  }
}
// Message fallback can now execute

Test Coverage

  • Added test for details as non-object value to prevent regression

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…rror

Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance error handling in AddAttendanceDialog Improve type safety and fallback logic in isDutyLeaveConstraintError Feb 12, 2026
@devakesu devakesu marked this pull request as ready for review February 12, 2026 19:07
@devakesu devakesu self-requested a review as a code owner February 12, 2026 19:07
Copilot AI review requested due to automatic review settings February 12, 2026 19:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines isDutyLeaveConstraintError to be safer under strict TypeScript settings while improving its fallback behavior when details exists but isn’t a nested object.

Changes:

  • Changed the function parameter type to unknown and added runtime narrowing before property access.
  • Updated nested details handling to only inspect details.code/details.hint when details is an object, avoiding blocking message-based fallback.
  • Added a regression test covering details as a non-object value.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/lib/error-handling.ts Tightens input typing to unknown, adds runtime guards, and fixes fallback flow when details is truthy but not an object.
src/lib/tests/duty-leave-error-handling.test.ts Adds test coverage for details being a non-object while still allowing message fallback detection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@devakesu devakesu merged commit 1fa44b5 into 1.5.3 Feb 12, 2026
6 checks passed
@devakesu devakesu deleted the copilot/sub-pr-346 branch February 12, 2026 19:12
devakesu added a commit that referenced this pull request Feb 12, 2026
* chore: enhance error handling in AddAttendanceDialog

* Improve type safety and fallback logic in isDutyLeaveConstraintError (#347)

* Initial plan

* fix: improve type safety and error handling in isDutyLeaveConstraintError

Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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