Skip to content

Commit

Permalink
print recovered panics to stderr (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Apr 14, 2022
1 parent 93c76c2 commit 3e24327
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions protoio/uvarint_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"bufio"
"fmt"
"io"
"os"
"runtime/debug"

"github.com/gogo/protobuf/proto"

Expand All @@ -60,6 +62,7 @@ func NewDelimitedReader(r io.Reader, maxSize int) ReadCloser {
func (ur *uvarintReader) ReadMsg(msg proto.Message) (err error) {
defer func() {
if rerr := recover(); rerr != nil {
fmt.Fprintf(os.Stderr, "caught panic: %s\n%s\n", rerr, debug.Stack())
err = fmt.Errorf("panic reading message: %s", rerr)
}
}()
Expand Down
3 changes: 3 additions & 0 deletions protoio/uvarint_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ package protoio
import (
"fmt"
"io"
"os"
"runtime/debug"

"github.com/gogo/protobuf/proto"

Expand All @@ -54,6 +56,7 @@ func NewDelimitedWriter(w io.Writer) WriteCloser {
func (uw *uvarintWriter) WriteMsg(msg proto.Message) (err error) {
defer func() {
if rerr := recover(); rerr != nil {
fmt.Fprintf(os.Stderr, "caught panic: %s\n%s\n", rerr, debug.Stack())
err = fmt.Errorf("panic reading message: %s", rerr)
}
}()
Expand Down

0 comments on commit 3e24327

Please sign in to comment.