Skip to content
Prev Previous commit
Next Next commit
gen bundle once file created
  • Loading branch information
johnstcn committed Mar 1, 2024
commit 475eaa87c36fb13148d5b52353056b516f35d0cf
12 changes: 7 additions & 5 deletions cli/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func (r *RootCmd) support() *clibase.Cmd {

deps.AgentID = agt.ID

bun, err := support.Run(inv.Context(), &deps)
if err != nil {
return err
}

if outputPath == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do this even before we fetch the workspace from API since it's not used as part of the filename.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to do the up-front checks first; if the workspace doesn't even exist then there's no point in writing the file.

cwd, err := filepath.Abs(".")
if err != nil {
Expand All @@ -83,6 +78,13 @@ func (r *RootCmd) support() *clibase.Cmd {
}
zwr := zip.NewWriter(w)
defer zwr.Close()

bun, err := support.Run(inv.Context(), &deps)
if err != nil {
_ = os.Remove(outputPath) // best effort
return xerrors.Errorf("create support bundle: %w", err)
}

if err := writeBundle(bun, zwr); err != nil {
return xerrors.Errorf("write support bundle to %s: %w", outputPath, err)
}
Expand Down