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: Fail to unmarshal JSON arrays #4361

Closed
JoshStrobl opened this issue Jan 31, 2018 · 9 comments · Fixed by #4373
Closed

regression: Fail to unmarshal JSON arrays #4361

JoshStrobl opened this issue Jan 31, 2018 · 9 comments · Fixed by #4373
Milestone

Comments

@JoshStrobl
Copy link

As of Hugo 0.35, I am no longer able to parse a valid JSON file for use in .Site.Data.var. Running --debug reports:

WARN 2018/01/31 17:26:12 Failed to read data from mirrors.json/mirrors.json: json: cannot unmarshal array into Go value of type map[string]interface {}                                                
WARN 2018/01/31 17:26:12 Failed to read data from sws.json/sws.json: json: cannot unmarshal array into Go value of type map[string]interface {}

mirrors.json is saved in data/, with the contents of:

[
	{
		"Latitude": 52.3702,
		"Location": "Amsterdam",
		"Longitude": 4.8952,
		"Type": "official",
		"Url": "https://stroblindustries.com/isos/"
	},
	{
		"Latitude": 33.753746,
		"Location": "Atlanta",
		"Longitude": -84.386330,
		"Type": "official",
		"Url": "http://us.justin.id.au/iso/"
	},
	{
		"Latitude": 52.5200,
		"Location": "Germany",
		"Longitude": 13.4050,
		"Type": "community",
		"Url": "http://solus.veatnet.de/iso/"
	},
	{
		"Latitude": 51.507351,
		"Location": "London",
		"Longitude": -0.127758,
		"Type": "official",
		"Url": "https://soluslond1iso.stroblindustries.com/"
	},
	{
		"Latitude": 40.357298,
		"Location": "New Jersey",
		"Longitude": -74.667223,
		"Type": "community",
		"Url": "http://mirror.math.princeton.edu/pub/solus-iso/"
	},
	{
		"Latitude": 43.086002,
		"Location": "Rochester",
		"Longitude": -77.674538,
		"Type": "community",
		"Url": "https://mirrors.rit.edu/solus/images/"
	},
	{
		"Latitude": 37.7749,
		"Location": "San Francisco",
		"Longitude": -122.4194,
		"Type": "official",
		"Url": "https://solussf1iso.stroblindustries.com/"
	}
]

sws.json is saved in data/, with the contents of:

[
	{
		"episode": "10",
		"description": "The team talks about work done since the snapshot 2017.04.18.0, ferryd, cuppa, plans for the new site, and more.",
		"date": "Fri, 14 Apr 2017 01:33:12 +0300",
		"length": [
			"21474938",
			"43046701"
		],
		"twis": "/2017/04/24/this-week-in-solus-install-43"
	}
]

The failing to parse this JSON results in errors like:

ERROR 2018/01/31 17:26:12 error processing shortcode "theme/shortcodes/sundays-with-solus.html" for page "blog/2017-04-24-this-week-in-solus-install-43.md": template: theme/shortcodes/sundays-with-so
lus.html:6:10: executing "theme/shortcodes/sundays-with-solus.html" at <where $site.Data.sws...>: error calling where: can't iterate over <nil>

With the respective line that it's erroring having: {{ range where $site.Data.sws "episode" "==" $episode }}


I can confirm that it works as intended with Hugo 0.34, I released a blog not just yesterday, were both the Sundays with Solus shortcode, as well as Download mirrors dropdown work as intended. See https://solus-project.com/blog/ and https://solus-project.com/download/

@JoshStrobl
Copy link
Author

I can confirm that it's not a permissions issue for reading (no permissions were changed between blogging yesterday and building the site today). Here is a summarized output (removing irrelevant dir content) of ls -al data:

drwxrwxrwx  9 joshua joshua 4096 Dec  5 04:35 .
drwxrwxrwx 12 joshua joshua 4096 Jan 26 15:38 ..
-rw-rw-r--  1 joshua joshua 1085 Sep 21 12:09 mirrors.json
-rw-rw-r--  1 joshua joshua  308 May 14  2017 sws.json

@moorereason
Copy link
Contributor

Likely related to the change from interface{} to map[string]interface{} in hugolib.Page.update() from 91bb774. May have to roll that back. Should have had tests for this use case.

/cc @vassudanagunta

@bep bep added the Bug label Jan 31, 2018
@bep bep changed the title JSON parsing no longer functioning regression: Fail to unmarshal JSON arrays Jan 31, 2018
@bep bep added this to the v0.35.1 milestone Jan 31, 2018
@vassudanagunta
Copy link
Contributor

on it

@JoshStrobl
Copy link
Author

Thanks @vassudanagunta 😄

@vassudanagunta
Copy link
Contributor

OK, looking into this, while it is a regression, it worked before but partly out of luck, since parts of the code assume data files along with frontmatter are maps at the top level. Hence JSON arrays fail if you have two of them at the same level (#4366). A single JSON array file works, but not YAML (#3890, also forum discussion), which I confirmed in test. Other unmarshaling issues that may be connected/resolved together: #4138, #2441.

If I can't come up with a broader solution soon, I'll role back just enough of 91bb774 to fix your case.

@bep
Copy link
Member

bep commented Feb 1, 2018

@vassudanagunta any updates on this?

@vassudanagunta
Copy link
Contributor

vassudanagunta commented Feb 1, 2018

In progress. Mostly have it. I'll PR a proposed fix within a few hours when I get some free time.

@vassudanagunta
Copy link
Contributor

vassudanagunta commented Feb 1, 2018

@bep The main difficulty is that the various parsers (YAML, JSON, TOML) all behave differently. Getting close. What's the deadline? It would be nice to fix this rather than roll back (which trades one bug for another). If I get this right, I'll have squashed a number of bugs.

@bep bep closed this as completed in #4373 Feb 2, 2018
bep pushed a commit that referenced this issue Feb 2, 2018
*  Adds retro-coverage for #4361
*  Verifies open issues #4138, #3890, #4366, 4083
*  Removes test reliance on the very code it is testing (hugo/parser package).
   Expected results are now all built manually / are more precise.
   Tests can run against different versions (no linkage errs)
bep pushed a commit that referenced this issue Feb 2, 2018
This bug was introduced in Hugo 0.35.

Fixes #4361
@bep bep modified the milestones: v0.35.1, v0.36 Feb 3, 2018
@github-actions
Copy link

github-actions bot commented Mar 8, 2022

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 8, 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.

4 participants