Improved error logging

This commit is contained in:
Alex Yatskov 2016-08-21 12:54:44 -07:00
parent 739518ad77
commit f20984e6f0
4 changed files with 22 additions and 9 deletions

View File

@ -45,7 +45,7 @@ func (ctx *context) chain() {
var err error
filters, err = initializer.Initialize(ctx)
if err != nil {
ctx.gs.fault(nil, err)
ctx.gs.fault(ctx.plug.Name(), nil, err)
return
}
}
@ -77,10 +77,10 @@ func (ctx *context) chain() {
if accept {
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
ctx.gs.fault(f, err)
ctx.gs.fault("core", f, err)
}
if err := processor.Process(ctx, f); err != nil {
ctx.gs.fault(f, err)
ctx.gs.fault(ctx.plug.Name(), f, err)
}
} else {
ctx.output <- f
@ -93,7 +93,7 @@ func (ctx *context) chain() {
if finalizer, ok := ctx.plug.(Finalizer); ok {
if err := finalizer.Finalize(ctx); err != nil {
ctx.gs.fault(nil, err)
ctx.gs.fault(ctx.plug.Name(), nil, err)
}
}
}

View File

@ -85,11 +85,11 @@ func (gs *goldsmith) exportFile(f *file) error {
return nil
}
func (gs *goldsmith) fault(f *file, err error) {
func (gs *goldsmith) fault(name string, f *file, err error) {
gs.errorMtx.Lock()
defer gs.errorMtx.Unlock()
ferr := &Error{Err: err}
ferr := &Error{Name: name, Err: err}
if f != nil {
ferr.Path = f.path
}

View File

@ -25,6 +25,7 @@ package goldsmith
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"time"
@ -97,12 +98,18 @@ type Context interface {
}
type Error struct {
Err error
Name string
Path string
Err error
}
func (e Error) Error() string {
return e.Err.Error()
var path string
if len(e.Path) > 0 {
path = "@" + e.Path
}
return fmt.Sprintf("[%s%s]: %s", e.Name, path, e.Err.Error())
}
type Initializer interface {
@ -117,4 +124,6 @@ type Finalizer interface {
Finalize(ctx Context) error
}
type Plugin interface{}
type Plugin interface {
Name() string
}

View File

@ -26,6 +26,10 @@ import "path/filepath"
type loader struct{}
func (*loader) Name() string {
return "loader"
}
func (*loader) Initialize(ctx Context) ([]string, error) {
infos := make(chan fileInfo)
go scanDir(ctx.SrcDir(), infos)