add error-handling exercise#2732
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
| console.log = jest.fn(); | ||
|
|
||
| try { | ||
| processString(''); | ||
| } catch { | ||
| /* | ||
| intentionally left empty, | ||
| I expext this call to throw, | ||
| but only care about verifying that the finally block is executed | ||
| and clean up message logged. | ||
| */ | ||
| } | ||
|
|
||
| expect(console.log).toHaveBeenCalledWith('Resource cleaned up'); |
There was a problem hiding this comment.
I don't think this will work with the Browser Test Runner, but the idea is not wrong. I can help come up with an easy alternative to fix this.
…m/A-O-Emmanuel/javascript into implement-error-handling-exercise
BNAndras
left a comment
There was a problem hiding this comment.
I’m not a track maintainer here, just a friendly maintainer from elsewhere on Exercism. I made some more general comments, but whatever SleeplessBytes and Cool-Kat say is the final word. :)
…r-handling.spec.js
| @@ -0,0 +1,6 @@ | |||
| export const processString = (input) => { | |||
| //TODO: implement this | |||
There was a problem hiding this comment.
In all other stubs we throw new Error('...') (I don't recall the exact error message). We probably want to use that!
| throw new TypeError(); | ||
| } | ||
| if (input === '') { | ||
| throw new Error(); |
There was a problem hiding this comment.
We almost always want a message in an error. We don't need to test the exact message, but throwing an empty error is non-idiomatic.
| @@ -0,0 +1,9 @@ | |||
| export const processString = (input) => { | |||
| if (typeof input !== 'string') { | |||
| throw new TypeError(); | |||
There was a problem hiding this comment.
We almost always want a message in an error. We don't need to test the exact message, but throwing an empty error is non-idiomatic.
Co-authored-by: Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>
|
Hi @SleeplessByte thanks for your review, sorry it took this long for me to reply, just to clarify, when you say "The only issue I have is that this isn't actually handling any error!" do you mean that the function should include descriptive error messages rather than handling more complex error scenarios? |
|
@A-O-Emmanuel no worries! We are not in a hurry. Right now, the exercise wants you to throw errors. It doesn't want you to handle the error. Handling errors could be: try { } catch { }or promise.catch(...)or try { } finally { }or promise.finally(...) |
|
Oh, that's true, I'll just have to revert back to the way I did it before. Thanks for the clarification, I've learnt something today, "throwing errors and handling errors" are two different things, yeah, it makes sense, thank you. |
|
hi @Cool-Katt I've made changes and added more tests, please review, and sorry for the delay. |
|
Hi @Cool-Katt have you been able to review the changes I made? |
|
@A-O-Emmanuel Terribly sorry for the long delay! It shouldn't have taken me 5 months to rely, yikes 😬 I still stand by my previous suggestion, which is: Let me know if you still want to work on this? |
|
@Cool-Katt thanks for the comments, I will still work on it. by this weekend, I will create the commit with your suggestion, also, it's okay, I just thought you were busy. Thank you. |
…est for generic errors and test for error messages
…m/A-O-Emmanuel/javascript into implement-error-handling-exercise Updating local branch
|
@Cool-Katt I've just push the changes you requested, please review |
|
Hi @Cool-Katt @BNAndras @SleeplessByte @joshgoebel can anyone provide any feedback for this? |
Cool-Katt
left a comment
There was a problem hiding this comment.
The PR for adding a new exercise should ideally only touch the files relevant to the new exercise being added, so please don't change any of the other files (even if it's just formatting, we have an auto formatter for this).
Also, see comments bellow
| } | ||
|
|
||
| expect(error).toBeInstanceOf(Error); | ||
| expect(error.constructor).not.toBe(Error); |
There was a problem hiding this comment.
We only need this check of the three, but testing for a message is good in any case because we don't ant people to circumvent sending one.
Also, i feel like this should be the first test, followed by all the tests for the various error types and finally the two passing cases that test the functionality
There was a problem hiding this comment.
Okay, thank you, and for the other files, sorry about that, It was mistake, I didn.t even know the formater ran for everyfile.
| "uuid": "de1c75f2-2461-4347-b5ca-b3cfaafe4d79", | ||
| "practices": [], | ||
| "prerequisites": [], | ||
| "difficulty": 1 |
There was a problem hiding this comment.
set an appropriate difficulty level. You can cross reference on the site to see what level exercises show up al easy, medium or hard. (I don't remember the scale, sry)
There was a problem hiding this comment.
Okay, I'll do this later today, thank you
|
@A-O-Emmanuel Overall good stuff. Just needs a few very minor tweaks and we can finally merge this |
Co-authored-by: Cool-Katt <stani_s1@abv.bg>
Co-authored-by: Cool-Katt <stani_s1@abv.bg>
Co-authored-by: Cool-Katt <stani_s1@abv.bg>
|
HI @Cool-Katt I've implemented the changes you request, please check if they are up to the standard you want, thank you |
|
okay, doing that now |
|
@A-O-Emmanuel that was for the bot, but i got a typo. You don't have to do anything |
|
/format |
|
The "Format code" action has started running. |
|
The "Format code" action has finished running. |
|
For security reasons,
|
|
Okay, thank you |
|
@Cool-Katt so it will be merged? or any other thing i need to do? |
|
@A-O-Emmanuel Nothing else for you to do right now. If @SleeplessByte approves as well (since they requested some changes) we can merge this. |
|
Okay, but I think @SleeplessByte was waiting for you to approve, let me send him a message |
Implemented the Error Handling practice exercise with solution, tests, and documentation