gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.61k stars 7.52k forks source link

Warning about "IsSet with unsupported type" is not helpful #11794

Open pilhuhn opened 10 months ago

pilhuhn commented 10 months ago

Issue #8667 still applies in latest

❯ hugo
Start building sites …
hugo v0.121.1-00b46fed8e47f7bb0a85d7cfc2d9f1356379b740+extended darwin/amd64 BuildDate=2023-12-08T08:47:45Z VendorInfo=brew

WARN  calling IsSet with unsupported type "invalid" (<nil>) will always return false.

The fix in #8668 is valid , even if I'd do it this way:

diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go
--- a/tpl/collections/collections.go    (revision 6f13430d4a3b0d8b196f13958fbfb6478be1f3aa)
+++ b/tpl/collections/collections.go    (date 1702330109068)
@@ -396,7 +396,7 @@
            return av.MapIndex(kv).IsValid(), nil
        }
    default:
-       ns.deps.Log.Warnf("calling IsSet with unsupported type %q (%T) will always return false.\n", av.Kind(), c)
+       ns.deps.Log.Warnf("calling IsSet with unsupported type %q (%T) [Key: %q] will always return false.\n", av.Kind(), c, kv)
    }

    return false, nil

This allows to see that a key 'name' is invalid

❯ /Users/hrupp/golang/bin/hugo Start building sites … hugo v0.122.0-DEV-6f13430d4a3b0d8b196f13958fbfb6478be1f3aa darwin/amd64 BuildDate=2023-12-08T09:01:24Z

WARN calling IsSet with unsupported type "invalid" () [Key: "name"] will always return false.

which then allows me to look through my files to see that this is the culprit

                {{if isset .Site.Params.author "name"}}

which then allows me to see that indeed in hugo.toml, there is no section [params.author]. A better fix would be to also show the place of the issue, but with the above, the message can at least be used for debugging.

jmooring commented 10 months ago

@pilhuhn Please change the issue title.