Repository: gohugoio/hugo (language: go)

Issue:
Server panics when archetype is modified
### What version of Hugo are you using (`hugo version`)?

Hugo Version: `hugo v0.123.4+extended linux/amd64 BuildDate=unknown`
(Built using golang compiler as described here: [Build from source](https://gohugo.io/installation/linux/#build-from-source).

### Does this issue reproduce with the latest release?
Yes (I'm on the latest release).

### Environment

* OS: Fedora Linux
    * `uname -a`: `Linux HOSTNAME 6.7.6-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Feb 23 18:27:29 UTC 2024 x86_64 GNU/Linux`
* Path to folder: `/home/USERNAME/www/project.name`

### Project File Structure

```bash
.
├── archetypes
│   └── default.md
├── assets
│   ├── scripts
│   │   └── main.ts
│   └── scss
│       └── styles.scss
├── config
│   └── _default
│       ├── config.yml
│       ├── menus.yml
│       ├── params.yml
│       ├── security.yml
│       └── taxonomies.yml
├── content
│   ├── _index.md
│   ├── about.md
│   ├── privacy-policy.md
│   ├── terms-and-conditions.md
│   ├── artwork
│   │   ├── _index.md
│   │   └── 2023-01-01_40x60
│   │       └── img
│   │           ├── primary
│   │           │   └── primary_768x1024_00.jpg
│   │           └── secondary
│   └── updates
│       ├── _index.md
│       ├── event1
│       │   └── index.md
│       ├── event2
│       │   └── index.md
│       └── event3
│           ├── _index.md
│           └── subevent1
│               ├── event4.md
│               └── event5.md
├── data
│       └── .gitkeep
├── layouts
│   ├── 404.html
│   ├── _default
│   │   ├── baseof.html
│   │   ├── home.html
│   │   ├── list.html
│   │   └── single.html
│   ├── partials
│   │   └── menus
│   │       ├── basic
│   │       │   ├── recursion-full.html
│   │       │   ├── recursion-none.html
│   │       │   └── sectional.html
│   │       ├── iconographic
│   │       │   └── social-media.html
│   │       └── special-purpose
│   │           └── a11y-jump-navigation.html
│   └── shortcodes
├── static
│   ├── fonts
│   │   ├── afacad
│   │   │   ├── Afacad-SemiBold.ttf
│   │   │   └── afacad-normal.css
│   │   ├── fonts.css
│   │   └── rem
│   │       ├── REM-Black.ttf
│   │       └── rem-normal.css
│   └── img
│       ├── galleries
│       │   └── artwork
│       │       ├── 10.jpg
│       │       ├── 11.jpg
│       │       ├── 12.jpg
│       │       ├── 13.jpg
│       │       ├── 14.jpg
│       │       ├── 15.jpg
│       │       ├── 16.jpg
│       │       ├── 17.jpg
│       │       ├── 18.jpg
│       │       ├── 19.jpg
│       │       ├── 20.jpg
│       │       ├── 21.jpg
│       │       ├── 22.jpg
│       │       ├── 23.jpg
│       │       ├── 4.jpg
│       │       ├── 5.jpg
│       │       ├── 6.jpg
│       │       ├── 7.jpg
│       │       ├── 8.jpg
│       │       └── 9.jpg
│       └── logo
│               └── logo.jpg
├── themes
│   └── .gitkeep
├── package.json
├── postcss.config.js
├── tailwind.config.js
├── tsconfig.json
├── vite.config.js
└── yarn.lock
```

### Error Stack

```bash
                   | EN  
-------------------+-----
  Pages            | 34  
  Paginator pages  |  0  
  Non-page files   |  1  
  Static files     | 59  
  Processed images |  0  
  Aliases          |  0  
  Cleaned          |  0  

Built in 839 ms
Environment: "development"
Serving pages from disk
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) 
Press Ctrl+C to stop

Change detected, rebuilding site (#1).
2024-03-01 15:57:47.874 -0500
Total in 0 ms
panic: unknown component: "archetypes"

goroutine 86 [running]:
github.com/gohugoio/hugo/hugolib.(*HugoSites).processPartial.func3(0xc0005e4070?, 0x1?, 0x0)
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/hugolib/hugo_sites_build.go:796 +0x102b
github.com/gohugoio/hugo/hugolib.(*HugoSites).processPartial(0xc000a783c0, {0x3f09838, 0x5373ee0}, {0x3f10d50?, 0xc0000dd0e0}, 0xc00130ac80, 0xc00191b740, {0xc00178a060, 0x1, 0x1})
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/hugolib/hugo_sites_build.go:860 +0xb69
github.com/gohugoio/hugo/hugolib.(*HugoSites).process(0xc00191b740?, {0x3f09838, 0x5373ee0}, {0x3f10d50?, 0xc0000dd0e0?}, 0xc00130ac80, 0x60?, {0xc00178a060, 0x1, 0x1})
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/hugolib/hugo_sites_build.go:234 +0x15d
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func4()
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/hugolib/hugo_sites_build.go:141 +0xbd
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build(0xc000a783c0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0}, {0xc00178a060, ...})
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/hugolib/hugo_sites_build.go:152 +0x65b
github.com/gohugoio/hugo/commands.(*hugoBuilder).rebuildSites(0xc0009bec80, {0xc00178a060, 0x1, 0x1})
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/commands/hugobuilder.go:1007 +0x19b
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents.func6(0xc0009bec80, 0xc000123ad0)
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/commands/hugobuilder.go:859 +0x9b
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents(0xc0009bec80, 0xc000843500, 0xc00083a498, {0xc000590048, 0x1, 0x1}, 0x0?)
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/commands/hugobuilder.go:862 +0x13bf
github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher.func2()
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/commands/hugobuilder.go:347 +0x25d
created by github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher in goroutine 1
	/home/username/go/pkg/mod/github.com/gohugoio/hugo@v0.123.4/commands/hugobuilder.go:338 +0x4f0
error Command failed with exit code 2.
```

I didn't have this issue when I was running the prebuilt Hugo. That was version `0.111.3`.

### Steps to Reproduce

1. Install the Hugo version mentioned.
2. Setup hugo config into "divided" yml files (see the uploaded zip file) under `/config/_default` [config.zip](https://github.com/gohugoio/hugo/files/14466118/config.zip). It includes:
    * config.yml
    * menus.yml
    * params.yml
    * security.yml
    * taxonomies.yml
4. Setup some basic content. My project dir structure is provided above to help improve reproducability.
5. Startup Hugo Server using the following command (these are the options I'm using): `hugo serve -D -E -F --gc --disableFastRender --cleanDestinationDir --noHTTPCache --poll 1000ms`
6. Edit the `/archetypes/default.md` file - what I did was the following simple text change - from single space in the " " title replace function to two spaces, "  ":
    * from: `title: {{ replace .Name "-" " " | title }}`
    * to: `title: {{ replace .Name "-" "  " | title }}`
7. The server should crash at this point.

### Things I've Tried to Do

* I've deleted all archetype files including `/archetypes/default.md` and made an edit to a regular Page MD file and this works - `hugo server` **does not** crash anymore.
* If I put back the `default.md` file and update other content (like the `/content/privacy-policy.md` file), the server continues to work as expected.
* If I edit the `/archtetypes/default.md` file (as described in the Reproduction section above), then the server crashes.

This is not a really critical bug as far as I can tell, more of an inconvenience. I'm still testing things out though - I tried running `hugo new artwork/some-new-art/index.md` and this works properly AND, if `hugo server ...` is running in a second terminal, it still doesn't crash. The only thing that is making `hugo server` crash is actually making **any** sort of edit to an archetype file.

Here are my two archetype files:
* [artwork.md](https://github.com/gohugoio/hugo/files/14466237/artwork.md)
* [default.md](https://github.com/gohugoio/hugo/files/14466238/default.md)

Please let me know if any other assistance/info is needed. Thanks!


Discussion / hints:
Summary...

```text
hugo new site foo
cd foo
hugo server
```

In another terminal

```text
echo "foo" >> archetypes/default.md
```

This was not a problem with v0.122.0. Fails with v0.123.0 and later.

Fix patch:
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 382b1eed02b..ddc712a2d67 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -792,6 +792,8 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
 			// It's hard to determine the exact change set of this,
 			// so be very coarse grained for now.
 			changes = append(changes, identity.GenghisKhan)
+		case files.ComponentFolderArchetypes:
+			// Ignore for now.
 		default:
 			panic(fmt.Sprintf("unknown component: %q", pathInfo.Component()))
 		}


Test patch:
diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go
index 98a8d0949f8..f3b10cf18cc 100644
--- a/hugolib/rebuild_test.go
+++ b/hugolib/rebuild_test.go
@@ -1472,3 +1472,21 @@ all: {{ $ab.RelPermalink }}
 	b.AddFiles("assets/common/c3.css", "c3").Build()
 	b.AssertFileContent("public/ab.css", "abc1c2 editedc3")
 }
+
+func TestRebuildEditArchetypeFile(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableLiveReload = true
+-- archetypes/default.md --
+---
+title: "Default"
+---
+`
+
+	b := TestRunning(t, files)
+	// Just make sure that it doesn't panic.
+	b.EditFileReplaceAll("archetypes/default.md", "Default", "Default Edited").Build()
+}