Skip to content

Update shortcode to use try instead of .Err for Hugo 0.141+ compatibility #1505

@hash-noob

Description

@hash-noob

Describe the bug

While I was trying to run the repo locally. I encountered the following error:

Error: error building site: render: failed to render pages: render of "D:/CodeYourFuture/curriculum/org-cyf-guides/content/contributing/contributors/index.md" failed: "D:\CodeYourFuture\curriculum\common-theme\layouts\_default\single.html:4:12": execute of template failed: template: single.html:4:12: executing "main" at <.Content>: error calling Content: "D:\CodeYourFuture\curriculum\org-cyf-guides\content\contributing\contributors\index.md:11:1": failed to render shortcode "contributors": failed to process shortcode: "D:\CodeYourFuture\curriculum\common-theme\layouts\shortcodes\contributors.html:13:10": execute of template failed: template: _shortcodes/contributors.html:13:10: executing "_shortcodes/contributors.html" at <.Err>: can't evaluate field Err in type resource.Resource: Resource.Err was removed in Hugo v0.141.0 and replaced with a new try keyword, see https://gohugo.io/functions/go-template/try/

What is wrong with this content?

Hugo v0.141.0 removed support for .Err on resource.Resource types and introduced the try keyword as a replacement. The contributors.html shortcode currently uses .Err, which causes the site to break on newer Hugo versions with the following error:

How could this be fixed?
Refactor the shortcode to use the try pattern. This change will ensure forward compatibility with Hugo and prevent build errors for contributors using recent versions.

Link to content
https://gohugo.io/functions/go-template/try/

Additional context

I thought I would ask someone before refactoring the code.

Who else might need to know about this?
@SallyMcGrath @illicitonion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    👀 In review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions