Throwing an error (with error message) from a theme

I remember this being either discussed somewhere or even being implemented somehow: I would like to throw some kind of readable error with my theme. Let’s assume I have a search script included (Algolia) that requires an enable config parameter to enable it and then some configuration parameters (index name, api key) to work. If the user enables it, but forgets to add configuration for the index I would like to break the compilation with a readable note what is missing instead of Hugo’s “something somewhere went wrong”. Is it possible to do some kind of error message setup before trying to do something?

I think I can do a with configvar do something else show error end thingy, but this specific setup requires a javascript executed as template and people probably would not see anything printed there…

Also I would want it to show up on CLI. If possible.

Thinking more about this, something like

{{ with $var }}
// do something
{{ else }}
alert('yep, we got an error');
{{ end }}

might do the trick in this specific setup.

That does not change the underlying question :wink: wouldn’t it be nice to have a way to kill generation with a readable error message?

2 Likes

Great. I knew there was something like that :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.