-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Failures in getJSON crash the build instead of allowing the user to handle it. #7228
Comments
For additional data, the remote API service I'm calling does return the following when you give it a non-existent data field (using {"status":404,"message":"No data found for entryId: 6ZLE","link":"https://data.rcsb.org/redoc/index.html"} However, I feel that even if the API was down or the URL someone fed into simply did not exist at all, the |
Related to this (and partly repeating ideas from above, sorry), would it be possible to have
Use case
It's great to get some message that a resource couldn't be fetched, to e.g. remove deleted tweets IDs from content, but sometimes it halts work on other issues (e.g. I'm editing a post, and the build will fail because a tweet ID in another post is obsolete). |
I'm getting this error when a user deletes a tweet (custom template, not using a shortcode: I have a list of tweets ids and fetching them from the Twitter public API). It would be great to be able to handle the error instead of crashing the build. |
Tested on 0.72.0. The issue remains |
Same issue here:
Had a quick search, some effort was already devoted since #5643 , but the issue remains. Better to mark this issue as a bug. |
Since fdfa4a5 the following can be entered in a project's config to allow building a project even if a remote source called by
P.S. This issue needs to be closed. |
Good to know! |
With the above in a project's config the console will show a WARN for a missing |
That's great to hear! I'd need to test it more thoroughly to make sure it works correctly. @maelle when I originally made the issue, you can establish a fallback with a
which would fail since the @onedrawingperday do you know if a warning raised by |
I don't know the answer to your question and cannot test it at the moment. |
For cross reference: #7867 |
There will be no warning/error for that particular error situation if you add this to your config, which means that you need to do any error handling yourself (if you want, e.g.: {{ with getJson "...." }}
<!-- Do stuff on success -->
{{ else }}
{{ warnf "It failed" }}
{{ end }} |
@onedrawingperday @bep @maelle I just did a local build with the current master and can confirm that #7867 does fix the problem and the For anyone looking for this solution in the future for some version after 0.76.5
Thanks to everyone who replied and thanks to @bep for implementing a fix. |
I know its not a fix-fix, and the implementation was not meant for this problem, but it does work for this use case and does produce the behavior I was asking for, so I'll count it as a fix. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
As suggested in #5643 I am creating a new issue for this.
getJSON causes builds to fail and halt in the versions 0.68.3, 0.69.1 and 0.69.2 which I have tested it on. This happens when accessing a remote file at a HTTP address (have not tested for local json files, not my use case).
The use case I have is that we're checking a database through its REST API for the existence of an entry to pull some metadata, and falling back to local data if not present. However, the only way we can check for the existence is to make a query, and if it's not there, the
getJSON
errors, and the build halts.Specific error is this:
Failed to get JSON resource "https://data.rcsb.org/rest/v1/core/entry/": Failed to retrieve remote file: Not Found
.Supposedly #5648 was meant to fix this, but from what I'm reading never did it properly?
I don't know Go so I'm not sure exactly how to fix it, but I think I can trace its stack:
getJson
callsgetResource
and then if an error is thrown its supposed to log said error but not throw the error:hugo/tpl/data/data.go
Lines 118 to 122 in c2d9fd1
getResource
attempts to callgetRemote
because the a URL was passed in, so the""
case is skipped and it goes to thedefault
:hugo/tpl/data/resources.go
Lines 109 to 122 in c2d9fd1
getRemote
detects anHTTPError
and actually throws the error, which passes back up the stack:hugo/tpl/data/resources.go
Lines 55 to 57 in c2d9fd1
getResource
andgetJSON
behave correctly and log the error, but the thing actually halting the build came from thegetRemote
call and theHTTPError
handling.I have a couple ideas on what behavior I would like to see to make this more user and use-case friendly.
getRemote
onHTTPError
not actually throw the error and instead log it, pass it back up and let the calling function handle it? Especially sincegetRemote
isn't a publicly available function in Hugo's shortcodes?getRemote
to pass it back up (like if there is another function invoking which could handle it?)getRemote
orgetJson
throw a warning instead? This does leave it up to the site developer to properly handle the case when the JSON they get back isn't what they expect, but I think that's a reasonable thing to ask for.with...else...end
construct to handle the return fromgetJSON
when it errors. This actually already works as expected. I can test it with the shortcode construct ofgetJSON
error, but also throw thewarnf
warning in the console. However, the fact that an error was thrown causes the built to fail in the end, but thegetJSON
error clearly is not fatal to the overall build code.getRemote
does this already to some extent, but make this return a boolean instead of the result or error?What version of Hugo are you using (
hugo version
)?0.68.3, 0.69.1 and 0.69.2 (currently using)
Sepcifically: Hugo Static Site Generator v0.69.2/extended darwin/amd64 installed via
brew
Does this issue reproduce with the latest release?
Yes: 0.69.2
The text was updated successfully, but these errors were encountered: