Skip to content

Make translation service more resilient against bad implementations #1671

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

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

SleeplessByte
Copy link
Member

With this change, a faulty implementation when calling the API results in the respective test failing with the following message:

Error: Expected callback function when calling fetch(text, callback), actual undefined.
    at new BadRequest (<solution>\api.js:122:5)
    at ExternalApi.request (<solution>\api.js:76:13)
    at TranslationService.request (<solution>\service.js:61:21)",

Without this change, the entire test run blows up and returns:

{
  "status": "error",
  "message": "Expected to run at least one test, but none were found. This can happen if the test file(s) (.spec.js) are missing or empty. These files are normally not empty. Revert any changes or report an issue if the problem persists.",
  "tests": [],
  "version": 3
}

Because under the hood it shows:

Determining test suites to run...<solution>\api.js:97       
      setTimeout(() => callback(this.values[text][0] ? undefined : makeRandomError()), 1);
                       ^

TypeError: callback is not a function
    at Timeout._onTimeout (<solution>\api.js:86:15)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

@SleeplessByte SleeplessByte added the x:action/improve Improve existing functionality/content label Feb 7, 2022
@SleeplessByte SleeplessByte requested a review from junedev February 7, 2022 05:40
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2022

Dear SleeplessByte

Thank you for contributing to the JavaScript track on Exercism! 💙
You will see some automated feedback below 🤖. It would be great if you can make sure your PR covers those points. This will save your reviewer some time and your change can be merged quicker.

  • 🧦 If you changed the function signature or the JSDoc comment in the exemplar file (.meta/exemplar.js) or the stub file (<exercise>.js), make sure the change is applied to both files.

  • ✍️ If your PR is not related to an existing issue (and is not self-explaining like a typo fix), please make sure the description explains why the change you made is necessary.

  • 🔤 If your PR fixes an easy to identify typo, if would be great if you could check for that typo in the whole repo. For example, if you found Unicdoe, use "replace all" in your editor (or command line magic) to fix it consistently.

Dear Reviewer/Maintainer

  • 📏 Make sure you set the appropriate x:size label for the PR. (This also works after merging, in case you forgot about it.)

  • 🔍 Don't be too nit-picky. If the PR is a clear improvement compared to the status quo, it should be approved as clear signal this is good to be merged even if the minor comments you might have are not addressed by the contributor. Further improvement ideas can be captured in issues (if important enough) and implemented via additional PRs.

  • 🤔 After reviewing the diff in the "Files changed" section, take a moment to think about whether there are changes missing from the diff. Does something need to be adjusted in other places so the code or content stays consistent?

Automated comment created by PR Commenter 🤖.

Copy link
Member

@junedev junedev left a comment

Choose a reason for hiding this comment

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

I would recommend you move all errors into api.js as discussed. Otherwise it seems a bit weird now that BadRequest is in api.js but the others are in errors.js.

But we can also do this later of course, so I'll approve anyway and you can decide how to proceed.

@SleeplessByte
Copy link
Member Author

Yeah, I want to do that separately, so we can try out the best way!

@SleeplessByte SleeplessByte merged commit 004945d into main Feb 7, 2022
@SleeplessByte SleeplessByte deleted the feature/translation-service-resilience branch February 7, 2022 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:action/improve Improve existing functionality/content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants