Skip to content

Panic with a misleading error on new page creation. ?When similar page exists? #12602

@bryndin

Description

@bryndin

I already had a content/about dir. Running hugo new content about.md freaks Hugo into panic.

  1. Error message is confusing [BUG] no Page found for "/home/db/projects/blog/content/about.md". Should it say the page exists without panicking? Not sure what is the expected behavior.
  2. The command did create about.md before failing (the timestamp matches the command execution time, see the prompt timer). Why did it make it if the about directory already exists? I'm new to Hugo and could be missing out, but I'd expect you can have either, not both.
  3. Why panic, not error?
─(17:36)─(db)──(git:db_use_my_fork_of_maupassant_theme ✱ ◼)────────────────────────────────────────────────────────────[/home/db/projects/blog]─
hugo new content about.md
panic: [BUG] no Page found for "/home/db/projects/blog/content/about.md"

goroutine 1 [running]:
github.com/gohugoio/hugo/create.(*contentBuilder).applyArcheType(0xc000789080, {0xc00013b6b0, 0x27}, {0x40e5fc0, 0xc000394f00})
        /build/hugo/parts/hugo/build/create/content.go:273 +0x354
github.com/gohugoio/hugo/create.(*contentBuilder).buildFile(0xc000789080)
        /build/hugo/parts/hugo/build/create/content.go:242 +0x1ad
github.com/gohugoio/hugo/create.NewContent.func1()
        /build/hugo/parts/hugo/build/create/content.go:103 +0x15f
github.com/gohugoio/hugo/create.NewContent(0xc000a0ba40, {0x0, 0x0}, {0x7fff4b38fdda, 0x8}, 0x0)
        /build/hugo/parts/hugo/build/create/content.go:106 +0x5c6
github.com/gohugoio/hugo/commands.newNewCommand.func1({0x0?, 0x0?}, 0x0?, 0xc000a0a640, {0xc000a8c500, 0x0?, 0x0?})
        /build/hugo/parts/hugo/build/commands/new.go:60 +0x15f
github.com/gohugoio/hugo/commands.(*simpleCommand).Run(0x0?, {0x40dabe8?, 0x5600620?}, 0x0?, {0xc000a8c500?, 0xc0009a1a28?, 0x0?})
        /build/hugo/parts/hugo/build/commands/commandeer.go:618 +0x3c
github.com/bep/simplecobra.(*Commandeer).compile.func1(0xc00091f300?, {0xc000a8c500?, 0x4?, 0x2932317?})
        /build/hugo/parts/hugo/go/pkg/mod/github.com/bep/simplecobra@v0.4.0/simplecobra.go:113 +0x4c
github.com/spf13/cobra.(*Command).execute(0xc000a6ef08, {0xc000a8c4c0, 0x1, 0x1})
        /build/hugo/parts/hugo/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc0007e1208)
        /build/hugo/parts/hugo/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        /build/hugo/parts/hugo/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1048
github.com/bep/simplecobra.(*Exec).Execute(0xc00088edd0, {0x40dabe8?, 0x5600620?}, {0xc000132010?, 0x101?, 0xc0000a4688?})
        /build/hugo/parts/hugo/go/pkg/mod/github.com/bep/simplecobra@v0.4.0/simplecobra.go:155 +0xd4
github.com/gohugoio/hugo/commands.Execute({0xc000132010, 0x3, 0x3})
        /build/hugo/parts/hugo/build/commands/commandeer.go:68 +0x2f9
main.main()
        /build/hugo/parts/hugo/build/main.go:25 +0x56
─(17:36)─(db)──(git:db_use_my_fork_of_maupassant_theme ✱ ◼)────────────────────────────────────────────────────────────[/home/db/projects/blog]─
hugo version
hugo v0.127.0-74e0f3bd63c51f3c7a0f07a7c779eec9e922957e+extended linux/amd64 BuildDate=2024-06-05T10:27:59Z VendorInfo=snap:0.127.0
─(17:38)─(db)──(git:db_use_my_fork_of_maupassant_theme ✱ ◼)────────────────────────────────────────────────────────────[/home/db/projects/blog]─
ll ~/projects/blog/content
total 20K
drwxr-xr-x 2 db db 4.0K Jun 15 02:26 about
drwxr-xr-x 2 db db 4.0K Jun 15 02:26 archives
drwxr-xr-x 2 db db 4.0K Jun 15 02:26 post
drwxr-xr-x 2 db db 4.0K Jun 15 02:26 search
-rw-r--r-- 1 db db  102 Jun 15 17:36 about.md
─(17:39)─(db)──(git:db_use_my_fork_of_maupassant_theme ✱ ◼)────────────────────────────────────────────────────────────[/home/db/projects/blog]─
ll ~/projects/blog/content/about
total 4.0K
-rw-r--r-- 1 db db 582 Jun 15 02:26 index.md
─(17:42)─(db)──(git:db_use_my_fork_of_maupassant_theme ✱ ◼)────────────────────────────────────────────────────────────[/home/db/projects/blog]─
hugo new content tmp.md
Content "/home/db/projects/blog/content/tmp.md" created

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

$ hugo version
hugo v0.127.0-74e0f3bd63c51f3c7a0f07a7c779eec9e922957e+extended linux/amd64 BuildDate=2024-06-05T10:27:59Z VendorInfo=snap:0.127.0

Does this issue reproduce with the latest release?

I presume 0.127.0 is the latest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions