Skip to content

Improve quality of error messages #13319

Open
@akbyrd

Description

@akbyrd

The error messages from Hugo consist of multiple "frames" all run together as a single line. It's really hard to visually parse.

Example:

ERROR render of "D:/Dev/akbyrd.dev/content/tests/6-test-emoji.md" failed: "D:\Dev\akbyrd.dev\layouts\_default\baseof.html:30:9": execute of template failed: template: _default/single.html:30:9: executing "_default/single.html" at <partial "resource" (dict "Name" "favicon.ico" "Rename" false)>: error calling partial: "D:\Dev\akbyrd.dev\layouts\partials\resource.html:67:24": execute of template failed: template: partials/resource.html:67:24: executing "partials/resource.html" at <$resource.Width>: error calling Width: this method is only available for image resources

In a terminal
Image

In a browser
Image

Honestly, I can't make heads or tails of this. Even trying to figure out where the line breaks should be is confusing. Maybe something like this?

ERROR
render of "D:/Dev/akbyrd.dev/content/tests/6-test-emoji.md" failed:
	"D:\Dev\akbyrd.dev\layouts\_default\baseof.html:30:9":
execute of template failed: template: _default/single.html:30:9:
	executing "_default/single.html" at <partial "resource" (dict "Name" "favicon.ico" "Rename" false)>:
	error calling partial: "D:\Dev\akbyrd.dev\layouts\partials\resource.html:67:24":
execute of template failed: template: partials/resource.html:67:24:
	executing "partials/resource.html" at <$resource.Width>:
	error calling Width: this method is only available for image resources

I think this is closer to ideal

ERROR Method "Width" is only available for image resources
	layouts/partials/resource.html:67:24:  at {{ $width = $resource.Width }}
	layouts/_default/baseof.html:30:9:     at {{ with partial "resource" (dict "Name" "favicon.ico" "Rename" false) -}}
	layouts/_default/single.html           
	content/tests/6-test-emoji.md:         

As it stands today

  • There's no visual line to follow for either locations or error messages
  • The same locations are listed multiple times.
  • Paths are sometimes relative and sometimes absolute
  • There are locations mentioned that don't even exist (single.html is 23 lines long)
  • Column numbers don't quite match reality (issues with whitespace maybe?)
  • Back and forward slashes are mixed, which makes searching with Ctrl+F harder.
  • Impractical to parse with an automated tool (e.g. a vscode problem matcher)

I don't know how much control Hugo has and how much this is dictated by Go templates, but I figure it's worth poking at.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions