Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Handle validation exceptions. #124

Merged
merged 7 commits into from
Apr 4, 2018

Conversation

RazzM13
Copy link
Contributor

@RazzM13 RazzM13 commented Mar 29, 2018

Fixed #121 and #122. Catches exceptions thrown in template validation and logs Unable to parse template! to stdout, if --verbose flag provided then logs the exception to stderr. In both cases the exit code is 1.

src/index.ts Outdated
try {
result = validator.validateFile(secondArg, options);
} catch(err) {
console.log('Unable to parse template!');
Copy link
Owner

Choose a reason for hiding this comment

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

I think something to spur the user on to resolve the issue would be helpful here.

"Unable to parse template! Is the template formatted correctly?"
"Unable to parse template! Does the path exist?"
"Unable to parse template! Use --verbose for more information."

Probably the last one is most useful.

Additionally, as we are now catching the file not found, it might be nice to return this as a separate error, so this parsing error is the last case "I've run into terrible difficulty" message, as opposed to something that could be encountered due to a typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds very nice. I believe that from a UX quality perspective the most specific messages are best for users however, they tend to become tedious to maintain therefore I'd like to lean on a combination of 3 and 2 implying that perhaps we should provide sufficiently specific messages for common scenarios such as invalid path and at the same time provide a broad catch-all type message for not really expected exceptions :) ... then again it's just a thought I think you have more experience with this project and perhaps see things more clearer than I do.

Copy link
Owner

Choose a reason for hiding this comment

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

I think

Unable to parse template! Use --verbose for more information. would work best for a general fall-through then.

Then we just need to add some extra logic to check if a path exists and return an error nicely.

Copy link
Contributor Author

@RazzM13 RazzM13 left a comment

Choose a reason for hiding this comment

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

How does this look? :)

@RazzM13 RazzM13 force-pushed the uncaught_exceptions branch from 744fd28 to 1ed832d Compare April 3, 2018 09:34
}
}
return errors[''];
}(err.message, {
Copy link
Owner

Choose a reason for hiding this comment

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

should this be indented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure... should it?

Copy link
Owner

Choose a reason for hiding this comment

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

Apparently not 👍

@martysweet
Copy link
Owner

Interesting build failure... any ideas?

@RazzM13
Copy link
Contributor Author

RazzM13 commented Apr 4, 2018

Trully sorry for not catching this sooner but I was expecting the build to fail due to the different error handling messages, which I would have fixed after you've approved the last change, but certainly not in that way.
I believe that the problem is that the safer-buffer polyfill did not mimick the real Buffer API as it should have and it was missing the constructor function which is why instanceof was failling; I've changed the polyfill in PR #130 and now it should be working.

@martysweet
Copy link
Owner

No worries

LGTM, just those tests to cleanup, ensuring the --verbose flag is throwing out a stack trace.

@RazzM13
Copy link
Contributor Author

RazzM13 commented Apr 4, 2018

I've just updated the tests with the new error messages and I've had to diverge from the non-existing file exception to a general parsing exception (i.e. invalid_yaml.yaml) due to the new behavior for that case. Also, when checking the --verbose functionality, I'm just trying to locate the specific exception message within stderr and not really parsing it as an exception that has a message and a strack trace; hoping this suffices if not, then perhaps you could direct me to an easy way of doing just that :)

@martysweet
Copy link
Owner

Good stuff!

@martysweet martysweet merged commit 78f61fe into martysweet:master Apr 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants