-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 errorf template func #3817
Comments
I think an /cc @moorereason |
Should |
It should log to the defined |
@bmon no panics/exits here. What you need to is just to log to We have some log counting magic going on behind the scenes, so any ERROR logging will exit -1 at the end. |
Add template function that will build a string from the given format string and arguments, then log it to ERROR. This has an intended side-effect of causing the build to fail, when executed. Resolves gohugoio#3817
Add template function that will build a string from the given format string and arguments, then log it to ERROR. This has an intended side-effect of causing the build to fail, when executed. Resolves gohugoio#3817
Add template function that will build a string from the given format string and arguments, then log it to ERROR. This has an intended side-effect of causing the build to fail, when executed. Resolves gohugoio#3817
Add template function that will build a string from the given format string and arguments, then log it to ERROR. This has an intended side-effect of causing the build to fail, when executed. Resolves #3817
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. |
I'm working on a heavily data-driven hugo site; virtually all the content is in front matter, and it's all relatively structured. As a result I tend to have a lot of templates, and they're more complicated than a blog or something where you mostly just need
{{ .Content }}
.One thing I've struggled a bit with is making sure the input data is formatted correctly. I'd like to add a bit of logic to my templates to verify that required properties exist and, if not, emit an error message. I was thinking something like
errorf
, which would be just likeprintf
but output to the console, and cause the build to fail. That way I could do something likeWithout this, sometimes Hugo will crash (e.g., if I try to dereference a null pointer) or emit an error message (e.g., passing an unset value to jsonify results in an error about an incorrect number of arguments), but often Hugo will just quietly keep going and I end up with bad data.
I know doing this in the template isn't really ideal, but the only other thing I can think of would be validating against a schema, but I'm not aware of anything for markdown (which is the front matter format I'm using)… Maybe a way to automatically convert front matter to JSON then validate it against a JSON schema?
The text was updated successfully, but these errors were encountered: