From 419d7cef8a04ca5a00f4468057968bb141763c65 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Mon, 10 Jul 2017 14:33:06 -0400 Subject: [PATCH] Rename PathError -> WrapPathError --- README.md | 2 ++ pipelines/pipeline.go | 6 +++--- site/data.go | 2 +- site/read.go | 17 +++++++---------- utils/ioutil.go | 6 +++--- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0245325..b4e22fe 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pipelines/pipeline.go b/pipelines/pipeline.go index 46fac22..58a0577 100644 --- a/pipelines/pipeline.go +++ b/pipelines/pipeline.go @@ -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", "") } diff --git a/site/data.go b/site/data.go index e3927e6..9e120ec 100644 --- a/site/data.go +++ b/site/data.go @@ -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 diff --git a/site/read.go b/site/read.go index fcb9b1c..ce4e2ea 100644 --- a/site/read.go +++ b/site/read.go @@ -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 } } } diff --git a/utils/ioutil.go b/utils/ioutil.go index c131ff2..75d6ff8 100644 --- a/utils/ioutil.go +++ b/utils/ioutil.go @@ -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 }