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

Hugo not recover from error after failed to parse invalid .Data #7043

Closed
pamubay opened this issue Mar 11, 2020 · 14 comments · Fixed by #9232
Closed

Hugo not recover from error after failed to parse invalid .Data #7043

pamubay opened this issue Mar 11, 2020 · 14 comments · Fixed by #9232

Comments

@pamubay
Copy link

pamubay commented Mar 11, 2020

Since you are working on #7042 , i believe this bug also in the same topic.

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

Hugo Static Site Generator v0.68.0-DEV-B1106F87/extended linux/amd64 BuildDate: 2020-03-11T08:17:58+0700

Does this issue reproduce with the latest release?

Yes.

When hugo failed to parse data in /data directory, Hugo not recover even after we fixed the invalid data

it happened to all three formats (toml,yaml,json)

Let's says we have this /data/testdata.json.

{
  "key": "value",
  "array": [
    "value1",
    "value2"
  ]
}

Reproducing The Bug

  1. Make it becomes invalid JSON by removing a comma or anything.
  2. Hugo throws ERROR.
ERROR 2020/03/11 08:42:34 failed to load data: failed to load data: "data-bug-reload/data/test_json.json:10:1": unmarshal failed: invalid character '"' after object key:value pair
  1. Fixed the JSON, make it valid JSON.
  2. HUGO still throwing ERROR.

but after editing a config file, Hugo trigger full rebuild, then the ERROR gone.

a repo to repoduce the bug

hugo-data-error-reload

@aBvezwegQZQHxnCkMuNfnBygvcwQqQoWwEvFbP
Copy link

Same error here as I missed a ":"
After saving config.toml Hugo triggered a rebuild and the error was gone.

Hugo Static Site Generator v0.68.3/extended darwin/amd64 BuildDate: unknown

MacOs 10.13.6 HighSierra

@stale
Copy link

stale bot commented Aug 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Aug 9, 2020
@pamubay
Copy link
Author

pamubay commented Aug 9, 2020

unstale bot 🤖

@stale stale bot removed the Stale label Aug 9, 2020
@stale
Copy link

stale bot commented Dec 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 19, 2020
@pamubay
Copy link
Author

pamubay commented Dec 19, 2020

unstale bot 🤖

@stale stale bot removed the Stale label Dec 19, 2020
@davidsneighbour
Copy link
Contributor

What you don't write @pamubay is, how you run your server. It might be that you run it with parameters that do not rebuild everthing on changes? If not, then this might be a data-directory watching issue.

@pamubay
Copy link
Author

pamubay commented Dec 19, 2020

its basic hugo server.

i even try --disableFastRender hopes Hugo always rebuild the whole site for each rebuild trigger. But doesnt work.

Hugo rebuild triggered after i changed the file under data/, but it still responds with the last ERROR about invalid data format.

except, we edit the config file, then Hugo will rebuild and works correctly.

hugo version:

Hugo Static Site Generator v0.80.0-DEV-81975F84/extended linux/amd64 BuildDate: 2020-12-18T07:42:21+0700

@davidsneighbour
Copy link
Contributor

Running hugo server - is the data directory in the list of watched locations that are printed by hugo?

@pamubay
Copy link
Author

pamubay commented Dec 19, 2020

Running hugo server - is the data directory in the list of watched locations that are printed by hugo?

Yes

@michidk
Copy link

michidk commented Mar 26, 2021

Just had the same issue on hugo v0.82.0+extended linux/amd64 BuildDate=unknown. Very annoying!

@dafeiroc
Copy link

Really interesting bug.

@HugoBelotDeloro
Copy link

Having this issue on hugo v0.89.3+extended linux/amd64, build date unknown.

ptgott added a commit to ptgott/hugo that referenced this issue Nov 21, 2021
When *Init.Do executes the *Init's f function, it stores the error
in the *Init's err field and returns ini.err. If we call an *Init's
Do method again, and there is no error in the subsequent call,
ini.err remains unchanged, and *Init.Do returns it again.

This becomes an issue for the "hugo server" command, which calls
h.init.data.Do within *HugoSites.Data every time the site is
rebuilt. If "hugo server" is started with a valid data file, and
that data file is edited to make it invalid (e.g., with poorly
formatted JSON), then any attempt to fix the data file only causes
Hugo to return the same error.

The fix is to ensure that *Init.Do resets ini.err to nil with each
call.

Fixes gohugoio#7043
ptgott added a commit to ptgott/hugo that referenced this issue Nov 21, 2021
When *Init.Do executes the *Init's f function, it stores the error
in the *Init's err field and returns ini.err. If we call an *Init's
Do method again, and there is no error in the subsequent call,
ini.err remains unchanged, and *Init.Do returns it again.

This becomes an issue for the "hugo server" command, which calls
h.init.data.Do within *HugoSites.Data every time the site is
rebuilt. If "hugo server" is started with a valid data file, and
that data file is edited to make it invalid (e.g., with poorly
formatted JSON), then any attempt to fix the data file only causes
Hugo to return the same error.

The fix is to ensure that *Init.Do resets ini.err to nil with each
call.

Fixes gohugoio#7043
ptgott added a commit to ptgott/hugo that referenced this issue Nov 30, 2021
When *Init.Do executes the *Init's f function, it stores the error
in the *Init's err field and returns ini.err. If we call an *Init's
Do method again, and there is no error in the subsequent call,
ini.err remains unchanged, and *Init.Do returns it again.

This becomes an issue for the "hugo server" command, which calls
h.init.data.Do within *HugoSites.Data every time the site is
rebuilt. If "hugo server" is started with a valid data file, and
that data file is edited to make it invalid (e.g., with poorly
formatted JSON), then any attempt to fix the data file only causes
Hugo to return the same error.

The fix is to ensure that *Init.Do resets ini.err to nil with each
call. The err field of lazy.Init is not used outside of *Init.Do,
so I removed it in order to simplify the code slightly and ensure
that errors would not be part of an *Init's state. Instead, this
change declares an error variable at the top of *Init.Do and
assigns it in place of ini.err.

After making this change, the go race detector began reporting
a race in TestImageOps between one goroutine created in
*Site.renderPages:

```go
go pageRenderer(ctx, s, pages, results, wg)
```

...and another goroutine created in *Init.withTimeout:

```go
	go func(cv chan verr) {
		v, err := f(ctx)
		c <- verr{v: v, err: err}
	}(c)
```

The race affected *pageContentOutput.content. To
prevent this race, I added getter and setter methods for
pageContentOutput.content that make use of a sync.RWMutex.
Otherwise, this field is assigned/read directly by multiple
goroutines.

I made other changes in order to refactor the code and prevent
unintentional memory sharing:

- Removed lazy.AddWithTimeout and its tests. This function is not
  called anywhere, and removing it makes it slightly easier to
  make sense of the lazy package.

- Edited the *Init.withTimeout to remove a redundant select
  statement.

- Edited *onceMore.Do to return an error, making it a bit
  more straightforward to share errors between its function
  argument and its caller without risking unintentional memory
  sharing.

Fixes gohugoio#7043
@darrenaddy
Copy link

darrenaddy commented Dec 1, 2021

Having this issue also.
Mine happened with the Tella theme.
Tella came with two slider slides on the home page, which I replaced with my own images and added a third, which was not showing up.
I was also looking for the default text that shows over the home page slides and found BOTH were in /data/slide.json

I changed the file from this:

[ { "title": "Tella, A Hugo Theme for Companies", "image": "img/slide/slide01.jpg" }, { "title": "Title Goes Here", "image": "img/slide/slide02.jpg" } ]
to this:
[ { "title": "My Changed Title, Slide 2", "image": "img/slide/slide01.jpg" }, { "title": "My Changed Title, Slide 2", "image": "img/slide/slide02.jpg" } { "title": "My Changed Title, Slide 3", "image": "img/slide/slide03.jpg" } ]

You can see I forgot to add the comma after 2nd array item. This threw the error:
failed to load data: failed to load data:
(Note the message is doubled).
followed by the path to the json file stating the error was on line 11:1
followed by
unmarshal failed: invalid character '{' after array element

I first added the needed comma and tried to reload the page. both by clicking the "Reload Page" link on the error page AND by doing a Force Reload with the browser. The page does not refresh.

I went back and removed my 3rd slide completely from the /data/slide.json (including the comma added after the 2nd slide) and saved it. I then again tried to reload the page. both by clicking the "Reload Page" link on the error page AND by doing a Force Reload with the browser. The page does not refresh - still shows the original error message.

Even attempting to load the site in another BROWSER results in the same original error message page.

Going back to my Command Prompt, I see that Hugo detected each change I made in the /data/slide.json document:
Change detected, rebuilding site.
The errors reported were:
`ERROR 2021/12/01 12:25:58 failed to load data: failed to load data: "D:\Hugo\HugoSites\cheeky\data\slide.json:11:1": unmarshal failed: invalid character '{' after array element
ERROR 2021/12/01 12:25:58 failed to load data: failed to load data: "D:\Hugo\HugoSites\cheeky\data\slide.json:11:1": unmarshal failed: invalid character '{' after array element
ERROR 2021/12/01 12:25:58 Rebuild failed:

ERROR 2021/12/01 12:25:58 Failed to load data: failed to load data: "D:\Hugo\HugoSites\cheeky\data\slide.json:11:1": unmarshal failed: invalid character '{' after array element
Total in 17 ms`

Killing Hugo (Windows: ctrl -C)
and restarting it with: Hugo server -D

Resulted in a solution. In fact, I changed the /data/slide.json file CORRECTLY and now the 3rd slide loads with my title.
(In my case, hugo's server now had to be called on a DIFFERENT localhost port (I had a different Hugo server running a different site on :1313) - so if you are simply reloading your original browser window you will now be getting a "This site can't be reached" error because localhost is no longer answering the previous port. Look carefully at the "Web Server is available at:" line in your terminal ).

bep added a commit to bep/hugo that referenced this issue Dec 2, 2021
To prevent sticky errors on server rebuilds.

Fixes gohugoio#7043
Closes gohugoio#9194
@bep bep closed this as completed in #9232 Dec 2, 2021
bep added a commit that referenced this issue Dec 2, 2021
To prevent sticky errors on server rebuilds.

Fixes #7043
Closes #9194
@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 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants