1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 21:34:45 +01:00

Markdown returns a wrapped error

This commit is contained in:
Oliver Steele 2017-08-22 11:00:46 -04:00
parent 32b1d0e7c4
commit c96587c05b
2 changed files with 35 additions and 3 deletions

View File

@ -2,10 +2,10 @@ package renderers
import (
"bytes"
"fmt"
"io"
"regexp"
"github.com/osteele/gojekyll/utils"
"github.com/russross/blackfriday"
"golang.org/x/net/html"
)
@ -39,7 +39,7 @@ func renderMarkdown(md []byte) ([]byte, error) {
)
html, err := renderInnerMarkdown(html)
if err != nil {
return nil, fmt.Errorf("%s while rendering markdown", err)
return nil, utils.WrapError(err, "markdown")
}
return html, nil
}

View File

@ -5,12 +5,40 @@ import (
"os"
)
// A WrappedError decorates an error with a message
type WrappedError interface {
error
Cause() error
}
// WrapError returns an error decorated with a message.
// If the error is nil, it returns nil.
func WrapError(err error, m string) error {
if err == nil {
return nil
}
return &wrappedError{cause: err, message: m}
}
type wrappedError struct {
cause error
message string
}
func (we *wrappedError) Cause() error {
return we.cause
}
func (we *wrappedError) Error() string {
return fmt.Sprintf("%s: %s", we.message, we.cause)
}
// A PathError is an error with a source path.
//
// An os.PathError is unfortunately not a PathError, but this is still
// useful for deciding whether to wrap other errors.
type PathError interface {
error
WrappedError
Path() string
}
@ -19,6 +47,10 @@ type pathError struct {
path string
}
func (pe *pathError) Cause() error {
return pe.cause
}
func (pe *pathError) Error() string {
return fmt.Sprintf("%s: %s", pe.path, pe.cause)
}