From 9e5ef18de434dbe011bee870f42f4934fa730656 Mon Sep 17 00:00:00 2001 From: Seth Back Date: Wed, 25 Jan 2023 10:01:07 -0800 Subject: [PATCH 1/3] rollback if nsc url is invalid --- cli/context_command.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/context_command.go b/cli/context_command.go index a18b3f42..b299cfc7 100644 --- a/cli/context_command.go +++ b/cli/context_command.go @@ -174,7 +174,15 @@ func (c *ctxCommand) editCommand(pc *fisk.ParseContext) error { return err } - return c.showCommand(pc) + // There was an error with some data in the modified config + // Save the known clean version and show the error + err = c.showCommand(pc) + if err != nil { + ctx.Save(c.name) + return err + } + + return nil } func (c *ctxCommand) renderListCompletion(current string, known []*natscontext.Context) { From ee1f972eda3036bc5a9092d5ee482e63a711720d Mon Sep 17 00:00:00 2001 From: Seth Back Date: Thu, 26 Jan 2023 07:41:30 -0800 Subject: [PATCH 2/3] updated error return --- cli/context_command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/context_command.go b/cli/context_command.go index b299cfc7..f8fb40f2 100644 --- a/cli/context_command.go +++ b/cli/context_command.go @@ -179,7 +179,7 @@ func (c *ctxCommand) editCommand(pc *fisk.ParseContext) error { err = c.showCommand(pc) if err != nil { ctx.Save(c.name) - return err + return fmt.Errorf("updated context validation failed - rolling back changes\n%w", err) } return nil From 7597989dcfffffe36662464e921b68f13b95ee90 Mon Sep 17 00:00:00 2001 From: Seth Back Date: Thu, 26 Jan 2023 08:08:45 -0800 Subject: [PATCH 3/3] update error return --- cli/context_command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/context_command.go b/cli/context_command.go index f8fb40f2..ea516172 100644 --- a/cli/context_command.go +++ b/cli/context_command.go @@ -179,7 +179,7 @@ func (c *ctxCommand) editCommand(pc *fisk.ParseContext) error { err = c.showCommand(pc) if err != nil { ctx.Save(c.name) - return fmt.Errorf("updated context validation failed - rolling back changes\n%w", err) + return fmt.Errorf("updated context validation failed - rolling back changes: %w", err) } return nil