Skip to content

Commit 5c20ac3

Browse files
committed
fix: add info message when controller does not support backup download
Rather than a 404 message, print a nice error message if attempting to download a backup archive from a 4.0 controller, or any other which does not support the action.
1 parent e716fb0 commit 5c20ac3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

api/client/backups/download.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/juju/errors"
1111
"gopkg.in/httprequest.v1"
1212

13+
apiservererrors "github.com/juju/juju/apiserver/errors"
1314
"github.com/juju/juju/rpc/params"
1415
)
1516

@@ -36,7 +37,7 @@ func (c *Client) Download(filename string) (io.ReadCloser, error) {
3637
&resp,
3738
)
3839
if err != nil {
39-
return nil, errors.Trace(err)
40+
return nil, errors.Trace(apiservererrors.RestoreError(err))
4041
}
4142
return resp.Body, nil
4243
}

cmd/juju/backups/download.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,21 @@ func (c *downloadCommand) Run(ctx *cmd.Context) error {
8888
// Download the archive.
8989
resultArchive, err := client.Download(c.RemoteFilename)
9090
if err != nil {
91+
if errors.Is(err, errors.NotFound) {
92+
ctx.Errorf("Download of backup archive files is not supported by this controller.")
93+
return nil
94+
}
9195
return errors.Trace(err)
9296
}
93-
defer resultArchive.Close()
97+
defer func() { _ = resultArchive.Close() }()
9498

9599
// Prepare the local archive.
96100
filename := c.ResolveFilename()
97101
archive, err := c.Filesystem().Create(filename)
98102
if err != nil {
99103
return errors.Annotate(err, "while creating local archive file")
100104
}
101-
defer archive.Close()
105+
defer func() { _ = archive.Close() }()
102106

103107
// Write out the archive.
104108
_, err = io.Copy(archive, resultArchive)

0 commit comments

Comments
 (0)