From 3f5a4a7827dddc7bf1c4baafd2ffb8a54f9cd492 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Sun, 18 Oct 2015 14:40:36 -0400 Subject: [PATCH] Fix NPE in SQL Quadstore When `tx.Exec` fails and an error is returned, result is nil. Thus, `result.RowsAffected()` panics. * Add a missing return statement in the error test. * Add a second missing return statement just below to return the proper error message if we can't execute `RowsAffected` instead of saying that the triple doesn't exist. --- graph/sql/quadstore.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graph/sql/quadstore.go b/graph/sql/quadstore.go index db5aaa4..a24d48e 100644 --- a/graph/sql/quadstore.go +++ b/graph/sql/quadstore.go @@ -216,10 +216,12 @@ func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.Igno d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label) if err != nil { glog.Errorf("couldn't exec DELETE statement: %v", err) + return err } affected, err := result.RowsAffected() if err != nil { glog.Errorf("couldn't get DELETE RowsAffected: %v", err) + return err } if affected != 1 && !opts.IgnoreMissing { return errors.New("deleting non-existent triple; rolling back")