Is there a way to beautify standard error console output

It would be much easier to debug Hugo sites if standard error messages were beautified in some way. For example, the error message below (message content is not relevant, just formatting)

Error: error building site: render: failed to render pages: render of "page" failed: "/site/layouts/_default/baseof.html:4:6": execute of template failed: template: _default/single.html:4:6: executing "_default/single.html" at <partial "head" .>: error calling partial: "/site/layouts/partials/head.html:8:4": execute of template failed: template: partials/head.html:8:4: executing "partials/head.html" at <partial "seo/structured-data" .>: error calling partial: "/site/layouts/partials/seo/structured-data.html:16:6": execute of template failed: template: partials/seo/structured-data.html:16:6: executing "partials/seo/structured-data.html" at <partial "seo/json-ld" .>: error calling partial: "/site/layouts/partials/seo/json-ld.html:1:14": execute of template failed: template: partials/seo/json-ld.html:1:14: executing "partials/seo/json-ld.html" at <partial "seo/utils/get-json-ld-dirty" .>: error calling partial: "/site/layouts/partials/seo/types/event.html:2:13": execute of template failed: template: partials/seo/types/event.html:2:13: executing "partials/seo/types/event.html" at <partialCached "seo/utils/get-type" $page $page.Permalink>: error calling partialCached: "/site/layouts/partials/seo/utils/get-type.html:3:7": execute of template failed: template: partials/seo/utils/get-type.html:3:7: executing "partials/seo/utils/get-type.html" at <.Param>: Param is not a method but has arguments

is currently rendered with soft line breaks in my console. But tt could be formatted like this:

Error: error building site: render: failed to render pages:
render of "page" failed: "/site/layouts/_default/baseof.html:4:6":
   execute of template failed: template: _default/single.html:4:6:
   executing "_default/single.html" at <partial "head" .>:
error calling partial: "/site/layouts/partials/head.html:8:4":
   execute of template failed: template: partials/head.html:8:4:
   executing "partials/head.html" at <partial "seo/structured-data" .>:
error calling partial: "/site/layouts/partials/seo/structured-data.html:16:6":
   execute of template failed: template: partials/seo/structured-data.html:16:6:
   executing "partials/seo/structured-data.html" at <partial "seo/json-ld" .>:
error calling partial: "/site/layouts/partials/seo/json-ld.html:1:14":
   execute of template failed: template: partials/seo/json-ld.html:1:14:
   executing "partials/seo/json-ld.html" at <partial "seo/utils/get-json-ld-dirty" .>:
error calling partial: "/site/layouts/partials/seo/types/event.html:2:13":
   execute of template failed: template: partials/seo/types/event.html:2:13:
   executing "partials/seo/types/event.html" at <partialCached "seo/utils/get-type" $page $page.Permalink>:
error calling partialCached: "/site/layouts/partials/seo/utils/get-type.html:3:7":
   execute of template failed: template: partials/seo/utils/get-type.html:3:7:
   executing "partials/seo/utils/get-type.html" at <.Param>:
Param is not a method but has arguments

Here I’ve just used line breaks, and in a arbitrary location, but it could be different. Anyway, line breaks themselves would perhaps suffice. This would immensely improve debugging with Hugo, and it seems straightforward to include.

You can do this yourself with something like:

hugo | sed 's/\: /\n\t/g' 

The above will change this:

Error: error building site: render: failed to render pages: render of "page" failed: "/home/jmooring/code/hugo-testing/layouts/_default/single.html:5:5": execute of template failed: template: _default/single.html:5:5: executing "main" at <partial "foo.html" .>: error calling partial: "/home/jmooring/code/hugo-testing/layouts/partials/foo.html:1:3": execute of template failed: template: partials/foo.html:1:3: executing "partials/foo.html" at <partial "bar.html" .>: error calling partial: "/home/jmooring/code/hugo-testing/layouts/partials/bar.html:1:3": execute of template failed: template: partials/bar.html:1:3: executing "partials/bar.html" at <partial "baz.html" .>: error calling partial: "/home/jmooring/code/hugo-testing/layouts/partials/baz.html:2:5": execute of template failed: template: partials/baz.html:2:5: executing "partials/baz.html" at <.Param>: can't evaluate field Param in type int

To this:

Error
        error building site
        render
        failed to render pages
        render of "page" failed
        "/home/jmooring/code/hugo-testing/layouts/_default/single.html:5:5"
        execute of template failed
        template
        _default/single.html:5:5
        executing "main" at <partial "foo.html" .>
        error calling partial
        "/home/jmooring/code/hugo-testing/layouts/partials/foo.html:1:3"
        execute of template failed
        template
        partials/foo.html:1:3
        executing "partials/foo.html" at <partial "bar.html" .>
        error calling partial
        "/home/jmooring/code/hugo-testing/layouts/partials/bar.html:1:3"
        execute of template failed
        template
        partials/bar.html:1:3
        executing "partials/bar.html" at <partial "baz.html" .>
        error calling partial
        "/home/jmooring/code/hugo-testing/layouts/partials/baz.html:2:5"
        execute of template failed
        template
        partials/baz.html:2:5
        executing "partials/baz.html" at <.Param>
        can't evaluate field Param in type int

And the above would be annoying, at best.

And the idea of somehow selectively adding newlines is not feasible. As seen above, these errors are deeply nested.

Thank you for the workaround, @jmooring ! I think it’s indeed feasible to add a newline everytime another stack level is printed, just as in many programming languages.

Not the way your workaround does, but in a way that turns easier to spot in which file the error originated from (not always the last file in the error message).

Not from my perspective.