Skip to content

Conversation

A-O-Emmanuel
Copy link

Implemented the Error Handling practice exercise with solution, tests, and documentation

This comment has been minimized.

@github-actions github-actions bot closed this Jul 24, 2025
@SleeplessByte SleeplessByte reopened this Jul 25, 2025
@SleeplessByte

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as off-topic.

This comment was marked as outdated.

Comment on lines 22 to 35
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');
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

okay, thank you

Copy link
Member

@BNAndras BNAndras left a comment

Choose a reason for hiding this comment

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

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. :)

@A-O-Emmanuel A-O-Emmanuel requested a review from BNAndras August 2, 2025 23:16
Copy link
Member

@SleeplessByte SleeplessByte left a comment

Choose a reason for hiding this comment

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

What's there is almost done. The only issue I have is that this isn't actually handling any error!

@@ -0,0 +1,6 @@
export const processString = (input) => {
//TODO: implement this
Copy link
Member

Choose a reason for hiding this comment

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

In all other stubs we throw new Error('...') (I don't recall the exact error message). We probably want to use that!

Copy link
Author

Choose a reason for hiding this comment

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

Okay

throw new TypeError();
}
if (input === '') {
throw new Error();
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, I'll add that

@@ -0,0 +1,9 @@
export const processString = (input) => {
if (typeof input !== 'string') {
throw new TypeError();
Copy link
Member

Choose a reason for hiding this comment

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

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.

@A-O-Emmanuel
Copy link
Author

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?

@SleeplessByte
Copy link
Member

@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(...)

@A-O-Emmanuel
Copy link
Author

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.

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.

3 participants