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

regression: Panic when "markup.highlight.linenos" set to table or inline #9518

Closed
kbyyd24 opened this issue Feb 17, 2022 · 6 comments · Fixed by #9540
Closed

regression: Panic when "markup.highlight.linenos" set to table or inline #9518

kbyyd24 opened this issue Feb 17, 2022 · 6 comments · Fixed by #9540

Comments

@kbyyd24
Copy link

kbyyd24 commented Feb 17, 2022

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.92.2+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

In my config.yml, the following config will reproduce the issue:

markup:
  highlight:
    linenos: table # or inline

Then run hugo server, got the follwing output:

❯ hugo server -p 4000
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x16041f2]

goroutine 1 [running]:
github.com/gohugoio/hugo/hugolib.newHugoSites({{0x261e550, 0xc0007ac810}, 0xc000785940, 0x0, {0x0, 0x0}, {0x2619a90, 0xc0004b7770}, {0x0, 0x0, ...}, ...}, ...)
        github.com/gohugoio/hugo/hugolib/hugo_sites.go:398 +0x832
github.com/gohugoio/hugo/hugolib.NewHugoSites({{0x261e550, 0xc0007ac810}, 0xc000785940, 0x0, {0x0, 0x0}, {0x2619a90, 0xc0004b7770}, {0x0, 0x0, ...}, ...})
        github.com/gohugoio/hugo/hugolib/hugo_sites.go:527 +0x11d
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig.func3()
        github.com/gohugoio/hugo/commands/commandeer.go:419 +0x4f8
sync.(*Once).doSlow(0xc0004b7770, 0x2135260)
        sync/once.go:68 +0xd2
sync.(*Once).Do(...)
        sync/once.go:59
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig(0xc0004140f0)
        github.com/gohugoio/hugo/commands/commandeer.go:377 +0x8a5
github.com/gohugoio/hugo/commands.newCommandeer(0x1, 0x1, 0x1, 0xc00019a1c0, {0x25c8620, 0xc000784a80}, 0xc00017f640, {0x0, 0x0, 0x0})
        github.com/gohugoio/hugo/commands/commandeer.go:195 +0x310
github.com/gohugoio/hugo/commands.initializeConfig(0x52, 0x65, 0x50, 0x213ab6b, {0x25c8620, 0xc000784a80}, 0xc00087fc88)
        github.com/gohugoio/hugo/commands/hugo.go:125 +0x31
github.com/gohugoio/hugo/commands.(*serverCmd).server(0xc000784a80, 0xc0003c7680, {0xc00087fcf0, 0x0, 0x0})
        github.com/gohugoio/hugo/commands/server.go:242 +0x1ce
github.com/spf13/cobra.(*Command).execute(0xc0003c7680, {0xc00017f600, 0x2, 0x2})
        github.com/spf13/[email protected]/command.go:856 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc0006aac80)
        github.com/spf13/[email protected]/command.go:974 +0x3bc
github.com/gohugoio/hugo/commands.Execute({0xc00003c090, 0x3, 0x3})
        github.com/gohugoio/hugo/commands/hugo.go:92 +0xb4
main.main()
        github.com/gohugoio/hugo/main.go:23 +0x58
@jmooring
Copy link
Member

First, the panic is new in v0.92.2. In v0.92.1 and earlier, your configuration produced:

Error: add site dependencies: create deps: 1 error(s) decoding:

  • cannot parse 'Highlight.LineNos' as bool: strconv.ParseBool: parsing "table": invalid syntax

Second, your configuration is invalid. In site configuration markup.highlight.lineNos is a boolean value. To enable line numbers and render the code in a table:

[markup.highlight]
lineNos = true
lineNumbersInTable = true

To enable line numbers and render them inline:

[markup.highlight]
lineNos = true
lineNumbersInTable = false

When using the highlight function in a template, the highlight shortcode in your markdown, or code fences in your markdown, you can use the short hand notation:

lineNos=inline
equivalent to lineNos=true and lineNumbersInTable=false

lineNos=table
equivalent to lineNos=true and lineNumbersInTable=true

@jmooring
Copy link
Member

Bisection indicates problem was introduced with a2a660e.

@kbyyd24
Copy link
Author

kbyyd24 commented Feb 19, 2022

Thank you @jmooring .

I think I misunderstood the document of highlight shortcode, the lineNos in shortcode is different with highlight config.

@kbyyd24 kbyyd24 closed this as completed Feb 19, 2022
@jmooring
Copy link
Member

@kbyyd24 I am re-opening this because the panic is a regression in a2a660e.

@jmooring jmooring reopened this Feb 19, 2022
@jmooring jmooring changed the title Get "panic: runtime error" when "markup.highlight.linenos" set to table or inline regression: Panic when "markup.highlight.linenos" set to table or inline Feb 19, 2022
@kbyyd24
Copy link
Author

kbyyd24 commented Feb 20, 2022

@kbyyd24 I am re-opening this because the panic is a regression in a2a660e.

Ok, np~

bep added a commit to bep/hugo that referenced this issue Feb 21, 2022
And now with a proper server test.

Fixes gohugoio#9518
Fixes gohugoio#9530
Fixes gohugoio#9539
bep added a commit to bep/hugo that referenced this issue Feb 21, 2022
And now with a proper server test.

Fixes gohugoio#9518
Fixes gohugoio#9530
Fixes gohugoio#9539
@bep bep closed this as completed in #9540 Feb 21, 2022
bep added a commit that referenced this issue Feb 21, 2022
And now with a proper server test.

Fixes #9518
Fixes #9530
Fixes #9539
@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 Mar 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants