summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-02 16:07:52 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-06 19:43:22 +0200
commitf2946da9e806c2bafbdd26707fe339db79bd980b (patch)
treeb5609317a861ea5f399e094e1b9287ca71dc22d1
parent6eea32bd6bc8e7a7dd07a8cb6a8343ae2c74aba0 (diff)
Improve error messages, esp. when the server is running
* Add file context to minifier errors when publishing * Misc fixes (see issues) * Allow custom server error template in layouts/server/error.html To get to this, this commit also cleans up and simplifies the code surrounding errors and files. This also removes the usage of `github.com/pkg/errors`, mostly because of https://github.com/pkg/errors/issues/223 -- but also because most of this is now built-in to Go. Fixes #9852 Fixes #9857 Fixes #9863
-rw-r--r--cache/filecache/filecache_config.go14
-rw-r--r--cache/filecache/filecache_pruner.go4
-rw-r--r--commands/commandeer.go17
-rw-r--r--commands/convert.go4
-rw-r--r--commands/hugo.go19
-rw-r--r--commands/new_site.go5
-rw-r--r--commands/server.go30
-rw-r--r--commands/server_errors.go61
-rw-r--r--common/herrors/error_locator.go132
-rw-r--r--common/herrors/error_locator_test.go38
-rw-r--r--common/herrors/errors.go26
-rw-r--r--common/herrors/file_error.go253
-rw-r--r--common/herrors/file_error_test.go46
-rw-r--r--common/herrors/line_number_extractors.go24
-rw-r--r--common/hugio/copy.go5
-rw-r--r--config/commonConfig.go5
-rw-r--r--config/configLoader.go7
-rw-r--r--create/content.go14
-rw-r--r--deploy/deploy.go3
-rw-r--r--deploy/deployConfig.go3
-rw-r--r--deps/deps.go13
-rw-r--r--helpers/path.go3
-rw-r--r--hugofs/decorators.go5
-rw-r--r--hugofs/fileinfo.go2
-rw-r--r--hugofs/rootmapping_fs.go6
-rw-r--r--hugofs/slice_fs.go5
-rw-r--r--hugofs/walk.go8
-rw-r--r--hugofs/walk_test.go2
-rw-r--r--hugolib/config.go5
-rw-r--r--hugolib/configdir_test.go2
-rw-r--r--hugolib/content_factory.go10
-rw-r--r--hugolib/content_map.go3
-rw-r--r--hugolib/content_map_page.go7
-rw-r--r--hugolib/fileInfo.go5
-rw-r--r--hugolib/filesystems/basefs.go10
-rw-r--r--hugolib/hugo_sites.go39
-rw-r--r--hugolib/hugo_sites_build.go10
-rw-r--r--hugolib/hugo_sites_build_errors_test.go108
-rw-r--r--hugolib/integrationtest_builder.go3
-rw-r--r--hugolib/page.go78
-rw-r--r--hugolib/page__meta.go3
-rw-r--r--hugolib/page__per_output.go7
-rw-r--r--hugolib/page__ref.go5
-rw-r--r--hugolib/page_unwrap.go4
-rw-r--r--hugolib/pages_process.go3
-rw-r--r--hugolib/paths/paths.go3
-rw-r--r--hugolib/shortcode.go31
-rw-r--r--hugolib/shortcode_test.go4
-rw-r--r--hugolib/site.go14
-rw-r--r--hugolib/site_render.go5
-rw-r--r--hugolib/testhelpers_test.go10
-rw-r--r--langs/config.go4
-rw-r--r--langs/i18n/translationProvider.go15
-rw-r--r--langs/language.go5
-rw-r--r--lazy/init.go2
-rw-r--r--markup/blackfriday/blackfriday_config/config.go5
-rw-r--r--modules/client.go33
-rw-r--r--modules/collect.go18
-rw-r--r--modules/config.go4
-rw-r--r--modules/npm/package_builder.go14
-rw-r--r--navigation/menu.go4
-rw-r--r--navigation/pagemenus.go5
-rw-r--r--output/outputFormat.go6
-rw-r--r--parser/metadecoders/decoder.go19
-rw-r--r--parser/pageparser/pageparser.go4
-rw-r--r--publisher/publisher.go3
-rw-r--r--releaser/releaser.go5
-rw-r--r--resources/image.go7
-rw-r--r--resources/images/color.go5
-rw-r--r--resources/images/config.go6
-rw-r--r--resources/images/image.go7
-rw-r--r--resources/page/page_generate/generate_page_wrappers.go8
-rw-r--r--resources/page/page_matcher.go4
-rw-r--r--resources/page/pages_related.go4
-rw-r--r--resources/page/permalinks.go2
-rw-r--r--resources/resource.go4
-rw-r--r--resources/resource_factories/create/remote.go14
-rw-r--r--resources/resource_metadata.go3
-rw-r--r--resources/resource_transformers/babel/babel.go6
-rw-r--r--resources/resource_transformers/integrity/integrity.go5
-rw-r--r--resources/resource_transformers/js/build.go15
-rw-r--r--resources/resource_transformers/js/options.go5
-rw-r--r--resources/resource_transformers/postcss/postcss.go16
-rw-r--r--resources/resource_transformers/templates/execute_as_template.go5
-rw-r--r--resources/resource_transformers/tocss/dartsass/transform.go12
-rw-r--r--resources/resource_transformers/tocss/scss/tocss.go5
-rw-r--r--resources/transform.go8
-rw-r--r--source/fileInfo.go7
-rw-r--r--source/filesystem.go5
-rw-r--r--tpl/collections/collections.go5
-rw-r--r--tpl/collections/merge.go9
-rw-r--r--tpl/collections/reflect_helpers.go5
-rw-r--r--tpl/collections/symdiff.go4
-rw-r--r--tpl/data/data.go8
-rw-r--r--tpl/data/resources.go5
-rw-r--r--tpl/images/images.go2
-rw-r--r--tpl/internal/resourcehelpers/helpers.go4
-rw-r--r--tpl/lang/lang.go5
-rw-r--r--tpl/openapi/openapi3/openapi3.go5
-rw-r--r--tpl/resources/resources.go7
-rw-r--r--tpl/strings/strings.go14
-rw-r--r--tpl/tplimpl/embedded/templates/server/error.html63
-rw-r--r--tpl/tplimpl/template.go15
-rw-r--r--tpl/tplimpl/template_ast_transformers.go10
-rw-r--r--tpl/tplimpl/template_errors.go20
-rw-r--r--tpl/transform/remarshal.go2
-rw-r--r--tpl/transform/unmarshal.go12
-rw-r--r--tpl/urls/urls.go3
-rw-r--r--transform/chain.go15
109 files changed, 858 insertions, 777 deletions
diff --git a/cache/filecache/filecache_config.go b/cache/filecache/filecache_config.go
index 816c6b8a6..a82133ab7 100644
--- a/cache/filecache/filecache_config.go
+++ b/cache/filecache/filecache_config.go
@@ -14,6 +14,7 @@
package filecache
import (
+ "fmt"
"path"
"path/filepath"
"strings"
@@ -25,8 +26,9 @@ import (
"github.com/gohugoio/hugo/helpers"
+ "errors"
+
"github.com/mitchellh/mapstructure"
- "github.com/pkg/errors"
"github.com/spf13/afero"
)
@@ -153,7 +155,7 @@ func DecodeConfig(fs afero.Fs, cfg config.Provider) (Configs, error) {
}
if err := decoder.Decode(v); err != nil {
- return nil, errors.Wrap(err, "failed to decode filecache config")
+ return nil, fmt.Errorf("failed to decode filecache config: %w", err)
}
if cc.Dir == "" {
@@ -162,7 +164,7 @@ func DecodeConfig(fs afero.Fs, cfg config.Provider) (Configs, error) {
name := strings.ToLower(k)
if !valid[name] {
- return nil, errors.Errorf("%q is not a valid cache name", name)
+ return nil, fmt.Errorf("%q is not a valid cache name", name)
}
c[name] = cc
@@ -197,12 +199,12 @@ func DecodeConfig(fs afero.Fs, cfg config.Provider) (Configs, error) {
if !v.isResourceDir {
if isOsFs && !filepath.IsAbs(v.Dir) {
- return c, errors.Errorf("%q must resolve to an absolute directory", v.Dir)
+ return c, fmt.Errorf("%q must resolve to an absolute directory", v.Dir)
}
// Avoid cache in root, e.g. / (Unix) or c:\ (Windows)
if len(strings.TrimPrefix(v.Dir, filepath.VolumeName(v.Dir))) == 1 {
- return c, errors.Errorf("%q is a root folder and not allowed as cache dir", v.Dir)
+ return c, fmt.Errorf("%q is a root folder and not allowed as cache dir", v.Di