From ea97df302f3931d3796b5a4344e6219dc787c835 Mon Sep 17 00:00:00 2001 From: Michael Golowka <72365+pcman312@users.noreply.github.com> Date: Mon, 7 Dec 2020 16:18:59 -0700 Subject: [PATCH] InfluxDB - Check for errors in the response too (#10384) --- plugins/database/influxdb/influxdb.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/database/influxdb/influxdb.go b/plugins/database/influxdb/influxdb.go index c58049ae4b..c8d0cc157c 100644 --- a/plugins/database/influxdb/influxdb.go +++ b/plugins/database/influxdb/influxdb.go @@ -102,13 +102,17 @@ func (i *Influxdb) NewUser(ctx context.Context, req dbplugin.NewUserRequest) (re "username": username, "password": req.Password, } - q := influx.NewQuery(dbutil.QueryHelper(query, m), "", "") - response, err := cli.Query(q) - if err != nil { + qry := influx.NewQuery(dbutil.QueryHelper(query, m), "", "") + response, err := cli.Query(qry) + // err can be nil with response.Error() being not nil, so both need to be handled + merr := multierror.Append(err, response.Error()) + if merr.ErrorOrNil() != nil { + // Attempt rollback only when the response has an error if response != nil && response.Error() != nil { attemptRollback(cli, username, rollbackIFQL) } - return dbplugin.NewUserResponse{}, fmt.Errorf("failed to run query in InfluxDB: %w", err) + + return dbplugin.NewUserResponse{}, fmt.Errorf("failed to run query in InfluxDB: %w", merr) } } } @@ -133,10 +137,10 @@ func attemptRollback(cli influx.Client, username string, rollbackStatements []st }), "", "") response, err := cli.Query(q) - if err != nil { - if response != nil && response.Error() != nil { - return err - } + // err can be nil with response.Error() being not nil, so both need to be handled + merr := multierror.Append(err, response.Error()) + if merr.ErrorOrNil() != nil { + return merr } } }