Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling in fetchDocById helper #867

Conversation

maximilianoertel
Copy link
Collaborator

@maximilianoertel maximilianoertel commented Oct 10, 2024

Proposed changes

This PR removes the swallowErrors parameter on the fetchByDocId helper to, well, prevent errors from being swallowed. Doing so and allowing the helper to throw any errors, enables any TanStack query using this helper function to properly handle error cases and trigger automatic retries.

As this parameter was only used in the validateCode method, this PR also slightly refactors that function to handle thrown errors.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (non-breaking change that does not add functionality but makes code cleaner or more efficient)
  • Documentation Update
  • Tests (new or updated tests)
  • Style (changes to code styling)
  • CI (continuous integration changes)
  • Repository Maintenance
  • Other (please describe below)

Checklist

  • I have read the guidelines for contributing.
  • The changes in this PR are as small as they can be. They represent one and only one fix or enhancement.
  • Linting checks pass with my changes.
  • Any existing unit tests pass with my changes.
  • Any existing end-to-end tests pass with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • If this PR fixes an existing issue, I have added a unit or end-to-end test that will detect if this issue reoccurs.
  • I have added JSDoc comments as appropriate.
  • I have added the necessary documentation to the roar-docs repository.
  • I have shared this PR on the roar-pr-reviews channel (if I have access)
  • I have linked relevant issues (if any)

Justification of missing checklist items

n/a

Further comments

n/a

Ref https://github.com/yeatmanlab/roar/issues/318

@maximilianoertel maximilianoertel requested a review from a team as a code owner October 10, 2024 21:14
Copy link

github-actions bot commented Oct 10, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 5.1% 390 / 7637
🔵 Statements 4.99% 421 / 8423
🔵 Functions 6.13% 115 / 1876
🔵 Branches 2.41% 110 / 4563
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
src/components/auth/RegisterStudent.vue 0% 0% 0% 0% 345-347, 349-353, 355, 360-361, 363-365, 364, 367-369, 368, 371-372, 374-399, 401-425, 428-451, 450, 454-458, 455-457, 456, 461-466, 462-465, 463-464, 470-471, 475-480, 476, 478-479, 483, 486, 488-528, 489, 491-496, 492-495, 498-506, 499-504, 501-503, 502, 505, 508, 510-513, 511-512, 515-527, 517-526, 518-524, 519-523, 525, 530-558, 532, 532, 534-557, 535, 537-543, 538-542, 545, 547-552, 548, 550-551, 554, 556, 560-572, 561, 563, 563, 565-569, 566, 568, 568, 571, 574-586, 575, 577, 577, 579-583, 580, 582, 582, 585, 588-604, 606-610, 612-619, 621, 623-628, 630-633, 635-638, 640-643, 646-667, 669, 671-682, 672-680, 673-679, 675-678, 681, 2-3, 6-7, 9, 16, 1, 49, 54-55, 64-65, 80, 84, 105, 127, 130, 132, 134, 160, 176, 178, 190, 194, 196, 207, 209-210, 220-221, 231, 233-234, 244-245, 255, 257-258, 268-269, 279, 281-282, 294, 305, 313, 1-11, 1-21, 32, 60, 1-68, 1-89, 1-115, 1-133, 1-139, 1-148, 1-165, 1-180, 1-191, 1-198, 1-212, 1-223, 1-236, 1-247, 1-260, 1-271, 1-284, 298, 308, 318, 1-321
src/helpers/query/utils.js 9.44% 0% 0% 10.43% 18-38, 29-37, 30-37, 32-37, 34, 34-37, 36, 36, 42-58, 44-54, 45-52, 51, 53, 55, 59, 59, 59, 70-72, 76-78, 90-92, 91, 100-102, 101, 104, 108-112, 114-120, 140-141, 143-148, 144-147, 150-152, 152-153, 155, 157-161, 160, 176-178, 178, 180-182, 184-186, 185, 188, 190-203, 191, 195-202, 201, 210-213, 211-212, 214-215, 217-230, 218-219, 219-229, 223-227, 226, 231, 235-237, 236, 239-241, 241-267, 250-266, 252-262, 253-261, 259, 263, 269, 269, 269, 269, 283, 285-286, 286-287, 289-307, 293-300, 295-298, 297, 303-306
Generated in workflow #654 for commit 1522135 by the Vitest Coverage Report Action

Copy link

github-actions bot commented Oct 10, 2024

Visit the preview URL for this PR (updated for commit 1522135):

https://roar-staging--pr867-ref-318-query-compos-t79uux7m.web.app

(expires Thu, 17 Oct 2024 22:02:25 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 2631e9c58fd0104ecbfddd72a62245ddac467460

Copy link

cypress bot commented Oct 10, 2024

roar-dashboard-e2e    Run #8171

Run Properties:  status check passed Passed #8171  •  git commit 1522135dc8: Component Tests for PR 867 "Fix error handling in `fetchDocById` helper" from co...
Project roar-dashboard-e2e
Run status status check passed Passed #8171
Run duration 02m 01s
Commit git commit 1522135dc8: Component Tests for PR 867 "Fix error handling in `fetchDocById` helper" from co...
Committer Maximilian Oertel
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 17

@maximilianoertel maximilianoertel added the enhancement New feature or request label Oct 10, 2024
@maximilianoertel maximilianoertel self-assigned this Oct 10, 2024
src/components/auth/RegisterStudent.vue Outdated Show resolved Hide resolved
src/components/auth/RegisterStudent.vue Outdated Show resolved Hide resolved
try {
const activationCode = await fetchDocById('activationCodes', studentCode, undefined, 'admin', true, true);

if (activationCode.orgId) {
state.students[outerIndex].orgName = `${_capitalize(activationCode.orgType)} - ${
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we guarantee that these properties of activationCode i.e. activationCode.orgType exist? Should we add fallbacks or optional chaining?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't add optional chaining here so that if activationCode.orgType doesn't exist, an error is thrown and caught by the catch block. There is definitely big room for improvement on the error handling, but, in my opinion, that should be done in a separate PR?

@maximilianoertel maximilianoertel changed the base branch from ref/318/query-composables to ref/318/query-composables-update October 10, 2024 21:58
Base automatically changed from ref/318/query-composables-update to ref/318/query-composables October 11, 2024 15:48
@maximilianoertel maximilianoertel added bug Something isn't working and removed enhancement New feature or request labels Oct 11, 2024
@maximilianoertel maximilianoertel merged commit 6750f9b into ref/318/query-composables Oct 11, 2024
22 checks passed
@maximilianoertel maximilianoertel deleted the ref/318/query-composables-fetch-error branch October 11, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants