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

Cast error for hugo new blabla/hello.md with custom theme (due to empty archetype file) #315

Closed
Diti opened this issue May 31, 2014 · 6 comments
Milestone

Comments

@Diti
Copy link

Diti commented May 31, 2014

Hello!

After creating a new theme and attempting to use Hugo's builder for content, I get the following error: ERROR: 2014/06/01 Unable to Cast <nil> to map[string]interface{}.

You can replicate the problem with Hugo v0.11 and the commands below.

hugo new site test && cd test
hugo new theme mytheme
printf 'theme = "mytheme"\n' >> config.toml
hugo new thispageworks.md
hugo new this/fails.md

Am I doing anything wrong? I think this may be a bug.

@Diti
Copy link
Author

Diti commented May 31, 2014

Actually, it's not a bug, it's a feature™.

Running the hugo new this/fails.md command doesn't fail if the current directory is the content/ one. I had read the documentation prior to posting this issue, but I had misunderstood that thing in bold:

This assumes it is being run from your working directory and the content path starts from your content directory.

@Diti Diti closed this as completed May 31, 2014
@anthonyfok anthonyfok added the Bug label Mar 25, 2015
@anthonyfok
Copy link
Member

Hi @Diti,

Thank you for your bug report. Actually, I think something could be done to improve the behaviour.
If I understand correctly, the same problem that @Diti experienced with v0.11 remains with us today with v0.14-DEV:

/tmp$ hugo new site test && cd test
/tmp/test$ hugo new theme mytheme
/tmp/test$ printf 'theme = "mytheme"\n' >> config.toml
/tmp/test$ hugo new thispageworks.md
ERROR: 2015/03/25 Error processing archetype file: /tmp/test/themes/mytheme/archetypes/default.md
ERROR: 2015/03/25 Unable to Cast <nil> to map[string]interface{}
/tmp/test$ hugo new this/fails.md
ERROR: 2015/03/25 Error processing archetype file: /tmp/test/themes/mytheme/archetypes/default.md
ERROR: 2015/03/25 Unable to Cast <nil> to map[string]interface{}

Reason? themes/mytheme/archetypes/default.md is empty, and hugo new does not like that.
Ditto with a malformed archetypes/default.md. For example, if I were to write just this line:

author = "Anthony Fok"

in my archetypes/default.md file, without the expected surrounding +++ for denoting TOML, hugo new would give me the same cryptic ERROR: 2015/03/25 Unable to Cast <nil> to map[string]interface{} error, which only a seasoned Go developer would understand. And no, we cannot / should not expect our Hugo end users to be Go developers.

I think one or both of the following should be done:

  1. hugo new theme should probably generate a proper archetypes/default.md file, or just leave it out altogether.
  2. hugo new [post] should catch a malformed archetype file error, and should explicitly tell the user that the archetype file is malformed instead of showing that cryptic error.

@anthonyfok anthonyfok reopened this Mar 25, 2015
@anthonyfok anthonyfok changed the title Cast error for hugo new blabla/hello.md with custom theme Cast error for hugo new blabla/hello.md with custom theme (due to empty archetype file) Mar 25, 2015
@anthonyfok anthonyfok added this to the v0.14 milestone Mar 25, 2015
@CMHarrington
Copy link

I'm getting the same error when copying/pasting the code from Step 1 here: http://gohugo.io/content/archetypes/ into a new document.

Saving to archetypes/default.md, then trying to create new post/newfrontmatter.md gives me the same error. ERROR: 2015/04/05 Unable to Cast <nil> to map[string]interface{}

I also heeded the caveats, and added an extra line after the end +++ hoping that would work, but it doesn't. (I don't seem to be getting an EOF error, rather a cast error as above)

FWIW, I've tried this on a linux machine (emacs), and on a mac (using BBEdit) Both are using standard unix LF for newlines.

@curtosis
Copy link

I'm getting this error as well with a custom theme. I have a valid archetype file (+++ fences and an extra empty line) in the theme.

@zachdyer
Copy link

I ran into this problem too. I just deleted the file. I don't think hugo new theme should create that file because it leads to this error and if it's not being used by create it.

@anthonyfok anthonyfok modified the milestones: v0.15, v0.14 Sep 16, 2015
lolindrath pushed a commit to lolindrath/hugo that referenced this issue Oct 14, 2015
To fix the cast error, create a minimal default.md in the archetype
folder.
@spf13 spf13 closed this as completed in fefd911 Oct 15, 2015
spf13 pushed a commit that referenced this issue Oct 15, 2015
fixes #315
To fix the cast error, create a minimal default.md in the archetype
folder.
dvoraq added a commit to dvoraq/greyshade that referenced this issue Nov 15, 2015
error when trying to create new post - gohugoio/hugo#315
bramp pushed a commit to bramp/hugo that referenced this issue Dec 17, 2015
fixes gohugoio#315
To fix the cast error, create a minimal default.md in the archetype
folder.
tychoish pushed a commit to tychoish/hugo that referenced this issue Aug 13, 2017
fixes gohugoio#315
To fix the cast error, create a minimal default.md in the archetype
folder.
@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 Apr 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants