From 61ec5f04563b6a79fbca7532ec511db7934941e2 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Thu, 21 Apr 2022 08:54:50 +0200 Subject: [PATCH] autopilot: correctly return errors within state functions. (#12714) --- nomad/state/autopilot.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/nomad/state/autopilot.go b/nomad/state/autopilot.go index ebb7e05bb..d53cfe5e0 100644 --- a/nomad/state/autopilot.go +++ b/nomad/state/autopilot.go @@ -49,10 +49,11 @@ func (s *StateStore) AutopilotSetConfig(index uint64, config *structs.AutopilotC tx := s.db.WriteTxn(index) defer tx.Abort() - s.autopilotSetConfigTxn(index, tx, config) + if err := s.autopilotSetConfigTxn(index, tx, config); err != nil { + return err + } - tx.Commit() - return nil + return tx.Commit() } // AutopilotCASConfig is used to try updating the Autopilot configuration with a @@ -76,10 +77,12 @@ func (s *StateStore) AutopilotCASConfig(index, cidx uint64, config *structs.Auto return false, nil } - s.autopilotSetConfigTxn(index, tx, config) + if err := s.autopilotSetConfigTxn(index, tx, config); err != nil { + return false, err + } - tx.Commit() - return true, nil + err = tx.Commit() + return err == nil, err } func (s *StateStore) autopilotSetConfigTxn(idx uint64, tx *txn, config *structs.AutopilotConfig) error {