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

tpl/data: Revise error handling in getJSON and getCSV #5199

Merged
merged 1 commit into from
Sep 11, 2018

Conversation

bep
Copy link
Member

@bep bep commented Sep 11, 2018

The most important part being: Log ERROR, but do not stop the build on remote errors.

Fixes #5076

@bep bep force-pushed the getjson-err branch 2 times, most recently from e182116 to 4290886 Compare September 11, 2018 07:02
@bep bep requested review from kaushalmodi and removed request for kaushalmodi September 11, 2018 07:33
@bep bep force-pushed the getjson-err branch 2 times, most recently from 78607a2 to 470d8c4 Compare September 11, 2018 08:17
@bep bep requested a review from kaushalmodi September 11, 2018 08:18
@bep bep force-pushed the getjson-err branch 2 times, most recently from 9d850b6 to 21e5dfe Compare September 11, 2018 12:08
@kaushalmodi
Copy link
Contributor

I just rebuilt hugo using this PR, but the build still fails on failing to fetch a remote JSON.

To test if the build doesn't error out, I randomly replaced some chars in a valid API URL. But I got errors like these:

ERROR 2018/09/11 08:26:57 Error while rendering "page" in "doc/": template: _default/examples.html:77:41: executing "main" at <getJSON (printf "%s/...>: error calling getJSON: Failed to retrieve remote file: Not Found

ERROR 2018/09/11 08:30:51 Error while rendering "page" in "doc/": template: _default/examples.html:69:41: executing "main" at <getJSON (printf "htt...>: error calling getJSON: Failed to retrieve remote file: Unauthorized

Copy link
Contributor

@kaushalmodi kaushalmodi left a comment

Choose a reason for hiding this comment

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

Build still fails when a URL doesn't point to a JSON

@kaushalmodi
Copy link
Contributor

Test snippet:

{{ $works := getJSON "https://gitlab.com/api/v4/projects/kaushalmodi%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master" }}
                    
{{ $failsUnauthorized := getJSON "https://gitlab.com/api/v5/projects/kaushalmodi%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master" }}
<!--                                                      ^ replaced v4 with v5 -->
{{ $failsNotFound := getJSON "https://gitlab.com/api/v4/projects/foo%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master" }}
<!--                                                             ^^^ replaced kaushalmodi with foo -->

The most important part being: Log ERROR, but do not stop the build on remote errors.

Fixes gohugoio#5076
@bep
Copy link
Member Author

bep commented Sep 11, 2018

Build still fails when a URL doesn't point to a JSON

You are right, I missed one. Fixe now.

@kaushalmodi
Copy link
Contributor

Thanks. Now hugo does not error out. But it still categorizes this as an Error, so it issues a non-zero exit code. This would fail Netlify build, as I see it failing my local Makefile based build too.

Serving the site on http://localhost:5554 ..
Building sites … ERROR 2018/09/11 09:23:23 Failed to get JSON resource https://gitlab.com/api/v5/projects/kaushalmodi%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master: Failed to retrieve remote file: Unauthorized
ERROR 2018/09/11 09:23:23 Failed to get JSON resource https://gitlab.com/api/v4/projects/foo%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master: Failed to retrieve remote file: Not Found
Error: Error building site: logged 2 error(s)
Total in 786 ms
make: *** [Makefile:153: server] Error 255

Can this be a Warning instead (I am assuming that warnings don't issue an error exit code)?

@bep
Copy link
Member Author

bep commented Sep 11, 2018

Can this be a Warning instead (I am assuming that warnings don't issue an error exit code)?

No, it is definitively an ERROR. I thought we agreed on that? You are free to ignore the exit code if you want. The main motivation behind this particular PR is to ... not stop the build on such errors.

@bep bep merged commit 43d4465 into gohugoio:master Sep 11, 2018
@kaushalmodi
Copy link
Contributor

kaushalmodi commented Sep 11, 2018

The whole point of that issue I opened was to build sites like normal even if getJSON failed to retrieve anything from the URL.

With the latest master, running hugo gives me:

Building sites … ERROR 2018/09/11 11:12:57 Failed to get JSON resource https://gitlab.com/api/v5/projects/kaushalmodi%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master: Failed to retrieve remote file: Unauthorized
ERROR 2018/09/11 11:12:58 Failed to get JSON resource https://gitlab.com/api/v4/projects/foo%2Fkaushalmodi.gitlab.io/repository/commits?path=content-org&ref_name=master: Failed to retrieve remote file: Not Found
Total in 1794 ms
Error: Error building site: logged 2 error(s)

This functionally just like before because Makefile/Netlify would not proceed on seeing that error code (even if the public/ gets populated after this commit).

You are free to ignore the exit code if you want.

I cannot also unconditionally mask errors else I will reach the deploy step for real errors too.

Can you please make this a warning?

@github-actions
Copy link

github-actions bot commented Feb 2, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2022
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.

getJSON etc. should log ERROR but return nil in failure situations
2 participants