mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
errors: Misc improvements
* Redo the server error template * Always add the content file context if relevant * Remove some now superflous error string matching * Move the server error template to _server/error.html * Add file context (with position) to codeblock render blocks * Improve JS build errors Fixes #9892 Fixes #9891 Fixes #9893
This commit is contained in:
@@ -137,6 +137,12 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
return errors.New(msg.Text)
|
||||
}
|
||||
path := loc.File
|
||||
if path == stdinImporter {
|
||||
path = ctx.SourcePath
|
||||
}
|
||||
|
||||
errorMessage := msg.Text
|
||||
errorMessage = strings.ReplaceAll(errorMessage, nsImportHugo+":", "")
|
||||
|
||||
var (
|
||||
f afero.File
|
||||
@@ -158,15 +164,16 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
fe := herrors.NewFileError(path, errors.New(msg.Text)).
|
||||
fe := herrors.
|
||||
NewFileError(path, errors.New(errorMessage)).
|
||||
UpdatePosition(text.Position{Offset: -1, LineNumber: loc.Line, ColumnNumber: loc.Column}).
|
||||
UpdateContent(f, herrors.SimpleLineMatcher)
|
||||
UpdateContent(f, nil)
|
||||
|
||||
f.Close()
|
||||
return fe
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s", msg.Text)
|
||||
return fmt.Errorf("%s", errorMessage)
|
||||
}
|
||||
|
||||
var errors []error
|
||||
|
Reference in New Issue
Block a user