Skip to content

Commit

Permalink
Summarize error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nownabe committed Nov 10, 2020
1 parent 2af4219 commit f503f15
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 13 deletions.
2 changes: 0 additions & 2 deletions extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ func newDefaultExtractor(ctx context.Context, project string) (extractor, error)
return &defaultExtractor{storage: s}, nil
}

// TODO: Summarize error log (use xerrors).
func (e *defaultExtractor) extract(ctx context.Context, ev Event) (io.Reader, func(), error) {
l := log.Ctx(ctx)

obj := e.storage.Bucket(ev.Bucket).Object(ev.Name)
r, err := obj.NewReader(ctx)
if err != nil {
l.Error().Msg(fmt.Sprintf("failed to initialize object reader: %v", err))
return nil, nil, xerrors.Errorf("failed to get reader of %s: %w", ev.FullPath(), err)
}
l.Debug().Msg(fmt.Sprintf("DEBUG r = %+v", r))
Expand Down
2 changes: 0 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (h *Handler) handle(ctx context.Context, e Event) error {

source, err := h.Parser(ctx, r)
if err != nil {
l.Error().Msg(fmt.Sprintf("[%s] failed to parse object: %v", h.Name, err))
return xerrors.Errorf("failed to parse: %w", err)
}
source = source[h.SkipLeadingRows:]
Expand All @@ -71,7 +70,6 @@ func (h *Handler) handle(ctx context.Context, e Event) error {
for i, r := range source {
record, err := h.Projector(i, r)
if err != nil {
l.Error().Msg(fmt.Sprintf("[%s] failed to project row %d: %v", h.Name, uint(i)+h.SkipLeadingRows, err))
return xerrors.Errorf("failed to project row %d (line %d): %w", i, uint(i)+h.SkipLeadingRows, err)
}

Expand Down
9 changes: 0 additions & 9 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"bytes"
"context"
"encoding/csv"
"fmt"

"cloud.google.com/go/bigquery"
"github.com/rs/zerolog/log"
"golang.org/x/xerrors"
)

Expand All @@ -32,14 +30,10 @@ func newDefaultLoader(ctx context.Context, project, dataset, table string) (load
return &defaultLoader{table: t}, nil
}

// TODO: Summarize log (use xerrors)
func (l *defaultLoader) load(ctx context.Context, records [][]string) error {
logger := log.Ctx(ctx)

// TODO: Make output format more efficient. e.g. gzip.
buf := &bytes.Buffer{}
if err := csv.NewWriter(buf).WriteAll(records); err != nil {
logger.Error().Msg(fmt.Sprintf("failed to write csv: %v", err))
return xerrors.Errorf("failed to write csv into buffer: %w", err)
}
rs := bigquery.NewReaderSource(buf)
Expand All @@ -48,18 +42,15 @@ func (l *defaultLoader) load(ctx context.Context, records [][]string) error {

job, err := loader.Run(ctx)
if err != nil {
logger.Error().Msg(fmt.Sprintf("failed to run bigquery load job: %v", err))
return xerrors.Errorf("failed to run bigquery load job: %w", err)
}

status, err := job.Wait(ctx)
if err != nil {
logger.Error().Msg(fmt.Sprintf("failed to wait job: %v", err))
return xerrors.Errorf("failed to wait bigquery job: %w", err)
}

if status.Err() != nil {
logger.Error().Msg(fmt.Sprintf("failed to load csv: %v", status.Errors))
return xerrors.Errorf("bigquery load job failed: %w", status.Err())
}

Expand Down

0 comments on commit f503f15

Please sign in to comment.