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

add try/catch to read helper #83

Merged
merged 3 commits into from
Jul 15, 2022
Merged

add try/catch to read helper #83

merged 3 commits into from
Jul 15, 2022

Conversation

KerenLerner
Copy link
Contributor

@KerenLerner KerenLerner commented Jul 8, 2022

Handle read exceptions more gracefully. Without this change, when a template tries to read a file that doesn't exist (e.g. an svg file), the entire page will fail to render, instead displaying this error message in the browser:

{
* 		errno: -2,
* 		syscall: "open",
* 		code: "ENOENT",
* 		path: "whatever/doesntexist.svg"
}

With this change, the page simply loads without the asset that doesn't exist and logs an error to the console.

index.js Outdated
try {
return fs.readFileSync(filename, 'utf-8');
} catch (error) {
console.log(`Failure to read ${filename}. Error: ${error}`);
Copy link
Member

Choose a reason for hiding this comment

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

should use clay log here.

@KerenLerner KerenLerner requested a review from james-owen July 8, 2022 15:52
Copy link
Member

@james-owen james-owen left a comment

Choose a reason for hiding this comment

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

I think this is fine to fix the issue we're having, but I'd like to dig more into why / where this issue is happening.

@KerenLerner
Copy link
Contributor Author

KerenLerner commented Jul 11, 2022

I think this is fine to fix the issue we're having, but I'd like to dig more into why / where this issue is happening.

Thanks for taking a look James. It was happening whenever we try to read a file that doesn't exist (say, a typo in the path to an SVG).

@KerenLerner KerenLerner merged commit 6a8283a into master Jul 15, 2022
@KerenLerner KerenLerner deleted the update-read-helper branch July 15, 2022 14:24
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.

4 participants