Skip to content

Commit 4865ebf

Browse files
committed
py: ExceptionInfo - check for nil
1 parent 5a57a8b commit 4865ebf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

py/exception.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func (e *Exception) Error() string {
106106

107107
// Go error interface
108108
func (e ExceptionInfo) Error() string {
109+
if e.Value == nil {
110+
return "ExceptionInfo{<nil>}"
111+
}
109112
if exception, ok := e.Value.(*Exception); ok {
110113
return exception.Error()
111114
}
@@ -114,9 +117,17 @@ func (e ExceptionInfo) Error() string {
114117

115118
// Dump a traceback for exc to w
116119
func (exc *ExceptionInfo) TracebackDump(w io.Writer) {
120+
if exc == nil {
121+
fmt.Fprintf(w, "Traceback <nil>\n")
122+
return
123+
}
117124
fmt.Fprintf(w, "Traceback (most recent call last):\n")
118125
exc.Traceback.TracebackDump(w)
119-
fmt.Fprintf(w, "%v: %v\n", exc.Type.Name, exc.Value)
126+
name := "<nil>"
127+
if exc.Type != nil {
128+
name = exc.Type.Name
129+
}
130+
fmt.Fprintf(w, "%v: %v\n", name, exc.Value)
120131
}
121132

122133
// Test for being set

0 commit comments

Comments
 (0)