Skip to content

Commit

Permalink
Merge pull request #5 from kayac/feature/add-error-handling
Browse files Browse the repository at this point in the history
Feature/add error handling
  • Loading branch information
fujiwara authored Mar 31, 2021
2 parents 6ea2c00 + 839c0d8 commit 0ed1b0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package router

import (
"encoding/json"
"log"
"fmt"
)

// LF represents LineFeed \n
Expand Down Expand Up @@ -44,8 +44,7 @@ func (e *jsonEncoder) Encode(rec record, _ []byte) error {

bytes, err := json.Marshal(rec)
if err != nil {
log.Println("[warn] failed to generate json record", err)
return err
return fmt.Errorf("json marshal: %w", err)
}
if _, err := e.body.Write(bytes); err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ func (r *Router) route(src io.Reader, s3url string) (map[destination]buffer, err
}
enc = r.option.newEncoder(body)
}
enc.Encode(rec, recordBytes)
if err := enc.Encode(rec, recordBytes); err != nil {
log.Printf("[warn] failed to encode %s record: %v\n", err, rec)
continue
}
encs[d] = enc
}
if err := scanner.Err(); err != nil {
Expand Down

0 comments on commit 0ed1b0e

Please sign in to comment.