1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-22 12:51:24 +01:00

Rename PathError -> WrapPathError

This commit is contained in:
Oliver Steele 2017-07-10 14:33:06 -04:00
parent f9c67a4272
commit 419d7cef8a
5 changed files with 16 additions and 17 deletions

View File

@ -81,6 +81,8 @@ These will probably not change:
By design:
- Having the wrong type in a `_config.yml` is an error.
- Plugins must be listed in the config file, not a Gemfile.
- `serve` generates pages on the fly; it doesn't write to the file system.
- Files are cached to `/tmp/gojekyll-${USER}`, not `./.sass-cache`
- Server live reload is always on.

View File

@ -82,12 +82,12 @@ func (p *Pipeline) Render(w io.Writer, b []byte, filename string, lineNo int, e
func (p *Pipeline) renderTemplate(src []byte, b map[string]interface{}, filename string, lineNo int) ([]byte, error) {
tpl, err := p.liquidEngine.ParseTemplate(src)
if err != nil {
return nil, utils.PathError(err, "Liquid Error", filename)
return nil, utils.WrapPathError(err, "Liquid Error", filename)
}
tpl.SetSourceLocation(filename, lineNo)
out, err := tpl.Render(b)
if err != nil {
return nil, utils.PathError(err, "Liquid Error", filename)
return nil, utils.WrapPathError(err, "Liquid Error", filename)
}
return out, err
}
@ -106,7 +106,7 @@ func (p *Pipeline) ApplyLayout(name string, data []byte, e map[string]interface{
})
data, err = tpl.Render(b)
if err != nil {
return nil, utils.PathError(err, "render template", name)
return nil, utils.WrapPathError(err, "render template", name)
}
name = templates.VariableMap(lfm).String("layout", "")
}

View File

@ -35,7 +35,7 @@ func (s *Site) readDataFiles() error {
var d interface{} // map or slice
err = utils.UnmarshalYAMLInterface(b, &d)
if err != nil {
return utils.PathError(err, "read YAML", filename)
return utils.WrapPathError(err, "read YAML", filename)
}
basename := utils.TrimExt(filepath.Base(f.Name()))
s.data[basename] = d

View File

@ -48,7 +48,6 @@ func (s *Site) Read() error {
// Reload reloads the config file and pages.
// It returns a copy.
// If there's an error loading the config file, it has no effect.
func (s *Site) Reload() (*Site, error) {
copy, err := FromDirectory(s.SourceDir(), s.flags)
if err != nil {
@ -60,12 +59,10 @@ func (s *Site) Reload() (*Site, error) {
// readFiles scans the source directory and creates pages and collection.
func (s *Site) readFiles() error {
s.Routes = make(map[string]pages.Document)
walkFn := func(filename string, info os.FileInfo, err error) error {
if err != nil {
return err
}
relname := utils.MustRel(s.SourceDir(), filename)
switch {
case info.IsDir() && s.Exclude(relname):
@ -76,24 +73,24 @@ func (s *Site) readFiles() error {
defaultFrontmatter := s.config.GetFrontMatterDefaults("", relname)
p, err := pages.NewFile(s, filename, filepath.ToSlash(relname), defaultFrontmatter)
if err != nil {
return utils.PathError(err, "read", filename)
return utils.WrapPathError(err, "read", filename)
}
s.AddDocument(p, true)
return nil
}
if err := filepath.Walk(s.SourceDir(), walkFn); err != nil {
return err
}
return s.ReadCollections()
}
// AddDocument adds a page to the site structures.
func (s *Site) AddDocument(p pages.Document, output bool) {
if p.Published() || s.config.Unpublished {
s.docs = append(s.docs, p)
// AddDocument adds a document to the site structures.
// It ignores unpublished documents unless config.Unpublished is true.
func (s *Site) AddDocument(d pages.Document, output bool) {
if d.Published() || s.config.Unpublished {
s.docs = append(s.docs, d)
if output {
s.Routes[p.Permalink()] = p
s.Routes[d.Permalink()] = d
}
}
}

View File

@ -81,10 +81,10 @@ func NewPathError(op, name, text string) *os.PathError {
return &os.PathError{Op: op, Path: name, Err: errors.New(text)}
}
// PathError returns an instance of *os.PathError, by wrapping its argument
// WrapPathError returns an instance of *os.WrapPathError, by wrapping its argument
// if it is not already an instance.
// PathError returns nil for a nil argument.
func PathError(err error, op, name string) *os.PathError {
// WrapPathError returns nil for a nil argument.
func WrapPathError(err error, op, name string) *os.PathError {
if err == nil {
return nil
}