diff --git a/main.go b/main.go index 47261d5..555272f 100644 --- a/main.go +++ b/main.go @@ -67,8 +67,10 @@ func (r *ReadableStream) Close() (err error) { defer func() { // We don't want any errors to be thrown if the stream is already closed. recovery := recover() - if !strings.Contains(recovery.(string), "Can not close stream after closing or error") { - err = fmt.Errorf("panic: %v", recovery) + if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") { + if recovery != nil { + err = fmt.Errorf("panic: %v", recovery) + } } }() @@ -141,8 +143,10 @@ func (w *WritableStream) Close() (err error) { defer func() { // We don't want any errors to be thrown if the stream is already closed. recovery := recover() - if !strings.Contains(recovery.(string), "Can not close stream after closing or error") { - err = fmt.Errorf("panic: %v", recovery) + if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") { + if recovery != nil { + err = fmt.Errorf("panic: %v", recovery) + } } }() diff --git a/tests/main.go b/tests/main.go index 0c34e89..d646daf 100644 --- a/tests/main.go +++ b/tests/main.go @@ -21,6 +21,10 @@ func main() { return } fmt.Println(string(buffer)) + err = readStream.Close() + if err != nil { + fmt.Println(err) + } }() return nil @@ -34,6 +38,10 @@ func main() { fmt.Println(err) return } + err = writeStream.Close() + if err != nil { + fmt.Println(err) + } }() return nil