Hugo should exit with an error code in case of errors when building a website #740

Closed
anthonyfok opened this Issue Dec 26, 2014 · 13 comments

Comments

Projects
None yet
5 participants
@anthonyfok
Member

anthonyfok commented Dec 26, 2014

To help notify the user of problems when Hugo is run as an automated script on the web server, I think Hugo should exit with an error code if there are warnings/errors when building a website.

For example, due to a bug either in Hugo docs or in the source code, some error messages are displayed during a hugo run:

$ cd ~/git/hugo/docs
$ hugo
ERROR: 2014/12/26 Two or more menu items have the same name/identifier in "<map[interface {}]interface {} Value>" Menu. Identified as "Overview".
 Rename or set a unique identifier. 
ERROR: 2014/12/26 Two or more menu items have the same name/identifier in "<map[interface {}]interface {} Value>" Menu. Identified as "Ordering".
 Rename or set a unique identifier. 
0 draft content 
0 future content 
87 pages created 
15 tags created
0 groups created
in 214 ms
$ echo $?
0

The fact that the above returns an error code of 0 means that most automatic deployment scripts (except the really smart ones who grep strings like ERROR and WARNING in the hugo output) would fail to detect any errors, leaving potential build problems undetected.

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Dec 26, 2014

Member

Agree, but a note on the above error. This is related to the discussion near the end here:

#722

Member

bep commented Dec 26, 2014

Agree, but a note on the above error. This is related to the discussion near the end here:

#722

@anthonyfok

This comment has been minimized.

Show comment
Hide comment
@anthonyfok

anthonyfok Dec 26, 2014

Member

Good to know where this bug comes from. Thanks for letting me know!

Member

anthonyfok commented Dec 26, 2014

Good to know where this bug comes from. Thanks for letting me know!

@anthonyfok anthonyfok changed the title from Hugo should exit with an error code in case of errors when buildling a website to Hugo should exit with an error code in case of errors when building a website Jan 20, 2015

@flowchartsman

This comment has been minimized.

Show comment
Hide comment
@flowchartsman

flowchartsman Apr 8, 2015

It seems like there are two solutions to this problem:

  1. Audit the code, identifying all notable errors and setting a flag
  2. Patch jww to (optionally?) track whether or not an ERROR, CRITICAL or FATAL has been emitted and then use that to determine exit code.

Number 2 is certainly the easiest solution, but it would necessitate an issue there. Thoughts?

It seems like there are two solutions to this problem:

  1. Audit the code, identifying all notable errors and setting a flag
  2. Patch jww to (optionally?) track whether or not an ERROR, CRITICAL or FATAL has been emitted and then use that to determine exit code.

Number 2 is certainly the easiest solution, but it would necessitate an issue there. Thoughts?

@batmat

This comment has been minimized.

Show comment
Hide comment
@batmat

batmat Oct 6, 2015

Contributor

+1. Critical IMO: finding potential 404 and so on ahead of deployment is certainly one pros of SSG. It would be great to have that.
Just found this issue after noticing I had used an incorrect relref but Hugo would not fail to deploy the site (automated, in my case, as @anthonyfok rightly points out as an example), hence not alerting me.
Thanks and congrats again for Hugo!

Contributor

batmat commented Oct 6, 2015

+1. Critical IMO: finding potential 404 and so on ahead of deployment is certainly one pros of SSG. It would be great to have that.
Just found this issue after noticing I had used an incorrect relref but Hugo would not fail to deploy the site (automated, in my case, as @anthonyfok rightly points out as an example), hence not alerting me.
Thanks and congrats again for Hugo!

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Dec 2, 2015

Member

I think this situation should be better after:

#1502

Member

bep commented Dec 2, 2015

I think this situation should be better after:

#1502

@phil-opp

This comment has been minimized.

Show comment
Hide comment
@phil-opp

phil-opp Feb 17, 2016

Contributor

Is there any update on this? I want to update my page automatically via travis on every commit. But travis looks only at the exit status, so it happily deploys it even if many errors occured.

Contributor

phil-opp commented Feb 17, 2016

Is there any update on this? I want to update my page automatically via travis on every commit. But travis looks only at the exit status, so it happily deploys it even if many errors occured.

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 17, 2016

Member

@phil-opp see my last comment. What errors do you see that doesn't exit != 0 ?

Member

bep commented Feb 17, 2016

@phil-opp see my last comment. What errors do you see that doesn't exit != 0 ?

@phil-opp

This comment has been minimized.

Show comment
Hide comment
@phil-opp

phil-opp Feb 17, 2016

Contributor

Links to non-existing pages:

Started building site
ERROR: 2016/02/17 22:52:43 template_funcs.go:1167: No page found with path or logical name "does-not-exist.md".
0 draft content
0 future content
10 pages created
0 non-page files copied
0 paginator pages created
0 tags created
0 categories created
in 10348 ms
Contributor

phil-opp commented Feb 17, 2016

Links to non-existing pages:

Started building site
ERROR: 2016/02/17 22:52:43 template_funcs.go:1167: No page found with path or logical name "does-not-exist.md".
0 draft content
0 future content
10 pages created
0 non-page files copied
0 paginator pages created
0 tags created
0 categories created
in 10348 ms

@bep bep self-assigned this Feb 18, 2016

bep added a commit to bep/jWalterWeatherman that referenced this issue Feb 18, 2016

Add log counters
The use case in Hugo is to exit with an error code
when *any* ERROR logging has occured.

See gohugoio/hugo#740

@bep bep referenced this issue in spf13/jWalterWeatherman Feb 18, 2016

Closed

Add log counters #10

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 18, 2016

Member

This should help fix this:

spf13/jWalterWeatherman#10

/cc @spf13

Member

bep commented Feb 18, 2016

This should help fix this:

spf13/jWalterWeatherman#10

/cc @spf13

bep added a commit to bep/jWalterWeatherman that referenced this issue Feb 18, 2016

Add log counters
The use case in Hugo is to exit with an error code
when *any* ERROR logging has occured.

See gohugoio/hugo#740

bep added a commit to bep/jWalterWeatherman that referenced this issue Feb 23, 2016

Add log counters
The use case in Hugo is to exit with an error code
when *any* ERROR logging has occured.

See gohugoio/hugo#740
@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 24, 2016

Member

The maintainer of the log library we use seems to have abandoned it, so I have given up on that approach. I may revisit this later.

Member

bep commented Feb 24, 2016

The maintainer of the log library we use seems to have abandoned it, so I have given up on that approach. I may revisit this later.

@bep bep removed their assignment Feb 24, 2016

@phil-opp

This comment has been minimized.

Show comment
Hide comment
@phil-opp

phil-opp Feb 24, 2016

Contributor

Isn't it owned by the same owner as hugo?

Contributor

phil-opp commented Feb 24, 2016

Isn't it owned by the same owner as hugo?

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 27, 2016

Member

Isn't it owned by the same owner as hugo?

Yes ... or: The Hugo contributors owns Hugo.

Member

bep commented Feb 27, 2016

Isn't it owned by the same owner as hugo?

Yes ... or: The Hugo contributors owns Hugo.

bep added a commit to spf13/jWalterWeatherman that referenced this issue Mar 11, 2016

Add log counters
The use case in Hugo is to exit with an error code
when *any* ERROR logging has occured.

See gohugoio/hugo#740

@bep bep closed this in 7cd69aa Mar 11, 2016

@phil-opp

This comment has been minimized.

Show comment
Hide comment
@phil-opp

phil-opp Mar 11, 2016

Contributor

Thanks a lot!

Contributor

phil-opp commented Mar 11, 2016

Thanks a lot!

tychoish added a commit to tychoish/hugo that referenced this issue Aug 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment