Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dump template func for debugging #3957

Closed
bep opened this issue Oct 11, 2017 · 9 comments
Closed

Add dump template func for debugging #3957

bep opened this issue Oct 11, 2017 · 9 comments

Comments

@bep
Copy link
Member

bep commented Oct 11, 2017

See https://github.com/sanity-io/litter

The output is great (as below from a random test), but may be "too much" even for the advanced user:

&hugolib.Page{ // p0
  pageInit: &hugolib.pageInit{},
  Kind: "home",
  Pages: nil,
  Params: map[string]interface {}{
    "draft": false,
    "expirydate": time.Time{},
    "iscjklanguage": false,
    "lastmod": time.Time{},
    "outputs": output.Formats{ // p1210
      output.Format{
        Name: "JSON",
        MediaType: media.Type{
          MainType: "application",
          SubType: "json",
          Suffix: "json",
          Delimiter: ".",
        },
        Path: "",
        BaseName: "index",
        Rel: "alternate",
        Protocol: "",
        IsPlainText: true,
        IsHTML: false,
        NoUgly: false,
        NotAlternative: false,
      },
    },
    "publishdate": time.Time{},
    "title": "JSON Home",
  },
  Content: "\n\n<h1 id=\"doc\">Doc</h1>\n\nShortJSON\n\nOtherShort: <h1>Hi!</h1>\n",
  Summary: " Doc ShortJSON OtherShort: Hi! ",
  TableOfContents: "<nav id=\"TableOfContents\">\n<ul>\n<li><a href=\"#doc\">Doc</a></li>\n</ul>\n</nav>",
  Aliases: nil,
  Images: nil,
  Videos: nil,
  Truncated: false,
  Draft: false,
  Status: "",
  PublishDate: time.Time{},
  ExpiryDate: time.Time{},
  PageMeta: hugolib.PageMeta{
    Weight: 0,
  },
  Markup: "markdown",
  Layout: "",
  Source: hugolib.Source{
    Frontmatter: nil,
    Content: nil,
    File: source.File{
      Contents: nil,
    },
  },
  Position: hugolib.Position{
    Prev: nil,
    Next: nil,
    PrevInSection: nil,
    NextInSection: nil,
  },
  GitInfo: nil,
  Site: &hugolib.SiteInfo{
    Taxonomies: hugolib.TaxonomyList{ // p34
      "categories": hugolib.Taxonomy{
      },
      "en": hugolib.Taxonomy{
      },
      "tags": hugolib.Taxonomy{
      },
    },
    Authors: hugolib.AuthorList{
    },
    Social: hugolib.SiteSocial{ // p1204
    },
    PageCollections: &hugolib.PageCollections{ // p35
      Pages: hugolib.Pages{
        p0,
      },
      AllPages: hugolib.Pages{ // p687
        p0,
        &hugolib.Page{ // p1
          pageInit: &hugolib.pageInit{},
          Kind: "home",
          Pages: nil,
          Params: map[string]interface {}{
            "draft": false,
            "expirydate": time.Time{},
            "iscjklanguage": false,
            "lastmod": time.Time{},
            "outputs": output.Formats{ // p1202
              output.Format{
                Name: "JSON",
                MediaType: media.Type{
                  MainType: "application",
                  SubType: "json",
                  Suffix: "json",
                  Delimiter: ".",
                },
                Path: "",
                BaseName: "index",
                Rel: "alternate",
                Protocol: "",
                IsPlainText: true,
                IsHTML: false,
                NoUgly: false,
                NotAlternative: false,
              },
            },
            "publishdate": time.Time{},
            "title": "JSON Nynorsk Heim",
          },
          Content: "\n\n<h1 id=\"doc\">Doc</h1>\n\nShortJSON\n\nOtherShort: <h1>Hi!</h1>\n",
          Summary: " Doc ShortJSON OtherShort: Hi! ",
          TableOfContents: "<nav id=\"TableOfContents\">\n<ul>\n<li><a href=\"#doc\">Doc</a></li>\n</ul>\n</nav>",
          Aliases: nil,
          Images: nil,
          Videos: nil,
          Truncated: false,
          Draft: false,
          Status: "",
          PublishDate: time.Time{},
          ExpiryDate: time.Time{},
          PageMeta: hugolib.PageMeta{
            Weight: 0,
          },
          Markup: "markdown",
          Layout: "",
          Source: hugolib.Source{
            Frontmatter: nil,
            Content: nil,
            File: source.File{
              Contents: nil,
            },
          },
          Position: hugolib.Position{
            Prev: nil,
            Next: nil,
            PrevInSection: nil,
            NextInSection: nil,
          },
          GitInfo: nil,
          Site: &hugolib.SiteInfo{
            Taxonomies: hugolib.TaxonomyList{ // p688
              "categories": hugolib.Taxonomy{
              },
              "en": hugolib.Taxonomy{
              },
              "tags": hugolib.Taxonomy{
              },
            },
            Authors: hugolib.AuthorList{
            },
            Social: hugolib.SiteSocial{ // p1196
            },
            PageCollections: &hugolib.PageCollections{ // p689
              Pages: hugolib.Pages{
                p1,
              },
              AllPages: p687,
              RegularPages: nil,
              AllRegularPages: nil,
            },
            Files: &nil, // p1197
            Menus: &hugolib.Menus{ // p691
            },
            Hugo: nil,
            Title: "Tittel på Nynorsk",
            RSSLink: "http://example.com/blog/index.xml",
            Author: map[string]interface {}{ // p1199
            },
            LanguageCode: "",
            DisqusShortname: "",
            GoogleAnalytics: "",
            Copyright: "",
            LastChange: time.Time{},
            Permalinks: hugolib.PermalinkOverrides{ // p1200
            },
            Params: map[string]interface {}{ // p690
              "languagename": "Nynorsk",
              "title": "Tittel på Nynorsk",
              "weight": 2,
            },
            BuildDrafts: false,
            Data: &map[string]interface {}{ // p43
            },
            Language: &helpers.Language{ // p40
              Lang: "nn",
              LanguageName: "Nynorsk",
              Title: "Tittel på Nynorsk",
              Weight: 2,
              Cfg: &viper.Viper{}, // p39
            },
            LanguagePrefix: "/nn",
            Languages: helpers.Languages{ // p41
              &helpers.Language{ // p38
                Lang: "en",
                LanguageName: "English",
                Title: "Title in English",
                Weight: 1,
                Cfg: p39,
              },
              p40,
            },
          },
          Title: "JSON Nynorsk Heim",
          Description: "",
          Keywords: []string{} // p3
,
          Data: map[string]interface {}{
            "Pages": nil,
          },
          Date: time.Time{},
          Lastmod: time.Time{},
          Sitemap: hugolib.Sitemap{
            ChangeFreq: "",
            Priority: -1,
            Filename: "",
          },
          URLPath: hugolib.URLPath{
            URL: "/",
            Permalink: "",
            Slug: "",
            Section: "",
          },
        },
      },
      RegularPages: nil,
      AllRegularPages: nil,
    },
    Files: &nil, // p1205
    Menus: &hugolib.Menus{ // p42
    },
    Hugo: nil,
    Title: "Title in English",
    RSSLink: "http://example.com/blog/index.xml",
    Author: map[string]interface {}{ // p1207
    },
    LanguageCode: "",
    DisqusShortname: "",
    GoogleAnalytics: "",
    Copyright: "",
    LastChange: time.Time{},
    Permalinks: hugolib.PermalinkOverrides{ // p1208
    },
    Params: map[string]interface {}{ // p36
      "languagename": "English",
      "title": "Title in English",
      "weight": 1,
    },
    BuildDrafts: false,
    Data: &p43, // p1209
    Language: p38,
    LanguagePrefix: "",
    Languages: p41,
  },
  Title: "JSON Home",
  Description: "",
  Keywords: p3,
  Data: map[string]interface {}{
    "Pages": nil,
  },
  Date: time.Time{},
  Lastmod: time.Time{},
  Sitemap: hugolib.Sitemap{
    ChangeFreq: "",
    Priority: -1,
    Filename: "",
  },
  URLPath: hugolib.URLPath{
    URL: "/",
    Permalink: "",
    Slug: "",
    Section: "",
  },
}
@bep bep added the Proposal label Oct 11, 2017
@moorereason
Copy link
Contributor

I'd be in favor of a general dump template function.

@bep bep changed the title Add Page.Dump for debugging Add dump template for debugging Oct 11, 2017
@kaushalmodi
Copy link
Contributor

kaushalmodi commented Dec 19, 2017

may be "too much" even for the advanced user

That might be alright is user can specify what they want to be printed. Assuming that the template fn name is dump, may be:

{{ dump .Params }} <!-- Print Page Params when called from a page template -->
{{ dump .GitInfo }} <!-- should also work for structs -->
{{ dump .File }}

I gave the above examples because I ended up creating something like dump but with whatever was available in user-land.. also printing structs needs the user to know the exact elements at the moment.

PS: The .File object is a special PITA as discussed on discourse.

@bep bep added Enhancement and removed Proposal labels Jan 14, 2018
@bep bep modified the milestones: v0.33, v0.34 Jan 14, 2018
@bep bep modified the milestones: v0.34, v0.35, v0.36 Jan 22, 2018
@bep bep modified the milestones: v0.36, v0.37 Feb 3, 2018
@bep bep changed the title Add dump template for debugging Add dump template func for debugging Feb 9, 2018
@regisphilibert
Copy link
Member

I agree with @kaushalmodi and @moorereason we should be able to print whatever with it.

It is just about presenting readable data to someone who knows what he is looking for.

@bep
Copy link
Member Author

bep commented Feb 10, 2018

It is just about presenting readable data to someone who knows what he is looking for.

Or someone who does not know what he is looking for finds something that looks interesting and starts using it and one of two things happens

  • I change a name, thinking: This cannot be used by anyone?
  • They don't understand what it returns and start a new thread on the forum saying ".Moo returns no value. I expect it to return something ... cow related maybe?"

@regisphilibert
Copy link
Member

regisphilibert commented Feb 10, 2018

Or someone who does not know what he is looking for finds something that looks interesting and starts using it and one of two things happens

Everybody is already using printf to do just that. (I didn't need a dump func to find about.Resource.AbsSourceFilename).

At least with your own dump function, you get to control what is printable and what is not. Would it be that hard to filter certain keys from the page context ? (chances are 90% of the time people will be dumping something from the page context)

PS: I don't agree with the filtering, but if it's a middle ground, I'll take it.

@bep
Copy link
Member Author

bep commented Feb 10, 2018

We have legacy history in Hugo with a liberal PR merge policy (with some additions' design looking sub-optimal in retrospect), exported fields/methods that should probably not been exported to the templates (AbsSourceFilename being one recent example; I should have spent the extra amount of work needed to hide it from the templates).

We have once said something in the line of "we merge this now, and see how it works -- if we like it, we document it." That model breaks once people learn how to use printf and GoDoc. But it is still true: If it is not documented on https://gohugo.io/, it is not recommended to use it. Because it may be removed/redesigned in the near future.

So, this dump function will only be added once I'm convinced that it reduces the net Hugo support traffic.

@bep bep modified the milestones: v0.37, v0.38 Feb 11, 2018
@bep bep modified the milestones: v0.38, v0.39 Feb 21, 2018
@bep bep modified the milestones: v0.39, v0.38 Mar 18, 2018
@bep bep modified the milestones: v0.38, v0.39 Apr 2, 2018
@bep bep added this to the v0.63 milestone Nov 28, 2019
@bep bep modified the milestones: v0.63, v0.64 Dec 11, 2019
@bep bep modified the milestones: v0.64, v0.65 Jan 22, 2020
@bep bep modified the milestones: v0.65, v0.66 Jan 30, 2020
@bep bep modified the milestones: v0.66, v0.67 Mar 2, 2020
@bep bep modified the milestones: v0.67, v0.68 Mar 9, 2020
@bep bep modified the milestones: v0.68, v0.69 Mar 20, 2020
@bep bep modified the milestones: v0.69, v0.70 Apr 8, 2020
@bep bep modified the milestones: v0.70, v0.71 Apr 28, 2020
@bep bep modified the milestones: v0.71, v0.72 May 18, 2020
@bep bep modified the milestones: v0.72, v0.73 May 31, 2020
@bep bep modified the milestones: v0.73, v0.74 Jun 23, 2020
@gerrywastaken
Copy link

gerrywastaken commented Jun 23, 2020

So, this dump function will only be added once I'm convinced that it reduces the net Hugo support traffic.

I don't know how it would be possible to prove this without testing it. Conversely I find it difficult to imagine a scenario where

but then stop and not use a variable because it wasn't formatted nicely.

I imagine most would do something similar to what I did... a couple of annoying search and replace operations in my editor to add new lines after {, } and ,. Found the variable I was looking for and then used that to find the appropriate documentation in the Gohugo docs.

The obfuscation of the data didn't stop me from using the variable, it just made me wonder why it was so poorly formatted.

gerrywastaken added a commit to ContainerSolutions/runbooks that referenced this issue Jul 1, 2020
There has unfortunately been some pushback with adding general debugging
tools to Hugo

gohugoio/hugo#4081 (comment)
gohugoio/hugo#3957 (comment)

I've found this can make things a lot more difficult than it needs
to be. There appears to be a belief that adding debugging tools will
lead to people using things that are undocumented. Unfortunately in my
experience I've had trouble with values that are documented but where
the documentation isn't very clear.

Even where debugging tools are provided the output is minified and
requests to change this have so far been rejected for the same reason as
above.

A user has developed a theme which can work around many of these issues
and add a convenient debugging partial to allow you to clearly see the
contents of most variables. (see README changes for more specifics.)
@bep bep closed this as completed in defd710 Jul 2, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants