mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
commands, hugolib, parser, tpl: Use errors.New instead of fmt.Errorf
This commit is contained in:
parent
1f130fd692
commit
dec1706ae0
6 changed files with 18 additions and 18 deletions
|
@ -14,6 +14,7 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
@ -100,7 +101,7 @@ func convertContents(mark rune) (err error) {
|
|||
panic("site.Source not set")
|
||||
}
|
||||
if len(site.Source.Files()) < 1 {
|
||||
return fmt.Errorf("No source files found")
|
||||
return errors.New("No source files found")
|
||||
}
|
||||
|
||||
contentDir := helpers.AbsPathify(viper.GetString("contentDir"))
|
||||
|
|
|
@ -15,7 +15,7 @@ package commands
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"errors"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -90,8 +90,7 @@ func undraftContent(p parser.Page) (bytes.Buffer, error) {
|
|||
// Front Matter
|
||||
fm := p.FrontMatter()
|
||||
if fm == nil {
|
||||
err := fmt.Errorf("Front Matter was found, nothing was finalized")
|
||||
return buff, err
|
||||
return buff, errors.New("Front Matter was found, nothing was finalized")
|
||||
}
|
||||
|
||||
var isDraft, gotDate bool
|
||||
|
@ -101,7 +100,7 @@ L:
|
|||
switch k {
|
||||
case "draft":
|
||||
if !v.(bool) {
|
||||
return buff, fmt.Errorf("not a Draft: nothing was done")
|
||||
return buff, errors.New("not a Draft: nothing was done")
|
||||
}
|
||||
isDraft = true
|
||||
if gotDate {
|
||||
|
@ -118,7 +117,7 @@ L:
|
|||
|
||||
// if draft wasn't found in FrontMatter, it isn't a draft.
|
||||
if !isDraft {
|
||||
return buff, fmt.Errorf("not a Draft: nothing was done")
|
||||
return buff, errors.New("not a Draft: nothing was done")
|
||||
}
|
||||
|
||||
// get the front matter as bytes and split it into lines
|
||||
|
@ -127,7 +126,7 @@ L:
|
|||
if len(fmLines) == 1 { // if the result is only 1 element, try to split on dos line endings
|
||||
fmLines = bytes.Split(fm, []byte("\r\n"))
|
||||
if len(fmLines) == 1 {
|
||||
return buff, fmt.Errorf("unable to split FrontMatter into lines")
|
||||
return buff, errors.New("unable to split FrontMatter into lines")
|
||||
}
|
||||
lineEnding = append(lineEnding, []byte("\r\n")...)
|
||||
} else {
|
||||
|
|
|
@ -898,7 +898,7 @@ var ErrHasDraftAndPublished = errors.New("both draft and published parameters we
|
|||
|
||||
func (p *Page) update(f interface{}) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("no metadata found")
|
||||
return errors.New("no metadata found")
|
||||
}
|
||||
m := f.(map[string]interface{})
|
||||
// Needed for case insensitive fetching of params values
|
||||
|
|
|
@ -1085,7 +1085,7 @@ func (s *Site) absPublishDir() string {
|
|||
|
||||
func (s *Site) checkDirectories() (err error) {
|
||||
if b, _ := helpers.DirExists(s.absContentDir(), hugofs.Source()); !b {
|
||||
return fmt.Errorf("No source directory found, expecting to find it at " + s.absContentDir())
|
||||
return errors.New("No source directory found, expecting to find it at " + s.absContentDir())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ package parser
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
toml "github.com/pelletier/go-toml"
|
||||
|
@ -32,7 +32,7 @@ type frontmatterType struct {
|
|||
|
||||
func InterfaceToConfig(in interface{}, mark rune) ([]byte, error) {
|
||||
if in == nil {
|
||||
return []byte{}, fmt.Errorf("input was nil")
|
||||
return []byte{}, errors.New("input was nil")
|
||||
}
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
|
@ -64,13 +64,13 @@ func InterfaceToConfig(in interface{}, mark rune) ([]byte, error) {
|
|||
}
|
||||
return b.Bytes(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Unsupported Format provided")
|
||||
return nil, errors.New("Unsupported Format provided")
|
||||
}
|
||||
}
|
||||
|
||||
func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
|
||||
if in == nil {
|
||||
return []byte{}, fmt.Errorf("input was nil")
|
||||
return []byte{}, errors.New("input was nil")
|
||||
}
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
|
@ -116,7 +116,7 @@ func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
|
|||
}
|
||||
return b.Bytes(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Unsupported Format provided")
|
||||
return nil, errors.New("Unsupported Format provided")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1676,13 +1676,13 @@ func prepareArg(value reflect.Value, argType reflect.Type) (reflect.Value, error
|
|||
func index(item interface{}, indices ...interface{}) (interface{}, error) {
|
||||
v := reflect.ValueOf(item)
|
||||
if !v.IsValid() {
|
||||
return nil, fmt.Errorf("index of untyped nil")
|
||||
return nil, errors.New("index of untyped nil")
|
||||
}
|
||||
for _, i := range indices {
|
||||
index := reflect.ValueOf(i)
|
||||
var isNil bool
|
||||
if v, isNil = indirect(v); isNil {
|
||||
return nil, fmt.Errorf("index of nil pointer")
|
||||
return nil, errors.New("index of nil pointer")
|
||||
}
|
||||
switch v.Kind() {
|
||||
case reflect.Array, reflect.Slice, reflect.String:
|
||||
|
@ -1693,7 +1693,7 @@ func index(item interface{}, indices ...interface{}) (interface{}, error) {
|
|||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
x = int64(index.Uint())
|
||||
case reflect.Invalid:
|
||||
return nil, fmt.Errorf("cannot index slice/array with nil")
|
||||
return nil, errors.New("cannot index slice/array with nil")
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot index slice/array with type %s", index.Type())
|
||||
}
|
||||
|
@ -1974,7 +1974,7 @@ func querify(params ...interface{}) (string, error) {
|
|||
qs := url.Values{}
|
||||
vals, err := dictionary(params...)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("querify keys must be strings")
|
||||
return "", errors.New("querify keys must be strings")
|
||||
}
|
||||
|
||||
for name, value := range vals {
|
||||
|
|
Loading…
Reference in a new issue