From 32a8874a29d270a3df9b5d25dcb82006e40adff7 Mon Sep 17 00:00:00 2001 From: David Sisson Date: Thu, 27 Apr 2017 21:40:44 -0700 Subject: [PATCH] Add proper error handling semantics to FileStream. --- runtime/Go/antlr/file_stream.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/runtime/Go/antlr/file_stream.go b/runtime/Go/antlr/file_stream.go index f4692ec9d..540cf5030 100644 --- a/runtime/Go/antlr/file_stream.go +++ b/runtime/Go/antlr/file_stream.go @@ -19,13 +19,19 @@ type FileStream struct { filename string } -func NewFileStream(fileName string) *FileStream { +func NewFileStream(fileName string) (*FileStream, error) { buf := bytes.NewBuffer(nil) - f, _ := os.Open(fileName) // Error handling elided for brevity. - io.Copy(buf, f) // Error handling elided for brevity. - f.Close() + f, err := os.Open(fileName) + if err != nil { + return nil, err + } + defer f.Close() + err = io.Copy(buf, f) + if err != nil { + return nil, er + } fs := new(FileStream) @@ -34,7 +40,7 @@ func NewFileStream(fileName string) *FileStream { fs.InputStream = NewInputStream(s) - return fs + return fs, nil }