aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/go/operation.go
diff options
context:
space:
mode:
authorGravatar Asim Shankar <ashankar@google.com>2017-05-16 13:08:04 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-05-16 13:11:36 -0700
commitfe41d05e7c8343ed53fc788d6c312792b390f679 (patch)
treeba75a55e572faa54391d7533d9ccd6335e56e671 /tensorflow/go/operation.go
parentd0b47889fb3a776dd6cf0a3c8360be9f84e2cbbb (diff)
Go: Keep errors in Go.
Helps with #9931 - graph.go: Return a nil Operation if the operation creation failed. This ensures that accidental usage of the nil operation results in a panic/stacktrace purely in Go (nil pointer dereference) instead of a SIGSEGV in the underlying C API. - operation.go: Attempt to help in the developer find the root cause of the nil pointer dereference with a chattier panic message. PiperOrigin-RevId: 156220056
Diffstat (limited to 'tensorflow/go/operation.go')
-rw-r--r--tensorflow/go/operation.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/tensorflow/go/operation.go b/tensorflow/go/operation.go
index e8f67c4f73..8fcad61f4c 100644
--- a/tensorflow/go/operation.go
+++ b/tensorflow/go/operation.go
@@ -113,6 +113,11 @@ func (p Output) Shape() Shape {
}
func (p Output) c() C.TF_Output {
+ if p.Op == nil {
+ // Attempt to provide a more useful panic message than "nil
+ // pointer dereference".
+ panic("nil-Operation. If the Output was created with a Scope object, see Scope.Err() for details.")
+ }
return C.TF_Output{oper: p.Op.c, index: C.int(p.Index)}
}