mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 14:17:42 +00:00
errcheck: More error handling
This commit is contained in:
parent
16313bfcc9
commit
3c753c071c
@ -63,9 +63,9 @@ func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup
|
||||
|
||||
stdout, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
// close first pipe
|
||||
r.Close()
|
||||
stdin.Close()
|
||||
// close first pipe and ignore subsequent errors
|
||||
_ = r.Close()
|
||||
_ = stdin.Close()
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
@ -197,8 +197,8 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
|
||||
err := cmd.Wait()
|
||||
debug.Log("Wait returned %v", err)
|
||||
be.waitResult = err
|
||||
// close our side of the pipes to rclone
|
||||
stdioConn.CloseAll()
|
||||
// close our side of the pipes to rclone, ignore errors
|
||||
_ = stdioConn.CloseAll()
|
||||
close(waitCh)
|
||||
}()
|
||||
|
||||
@ -237,13 +237,17 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
|
||||
|
||||
res, err := ctxhttp.Do(ctx, client, req)
|
||||
if err != nil {
|
||||
bg()
|
||||
// ignore subsequent errors
|
||||
_ = bg()
|
||||
_ = cmd.Process.Kill()
|
||||
return nil, errors.Errorf("error talking HTTP to rclone: %v", err)
|
||||
}
|
||||
|
||||
debug.Log("HTTP status %q returned, moving instance to background", res.Status)
|
||||
bg()
|
||||
err = bg()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error moving process to background: %w", err)
|
||||
}
|
||||
|
||||
return be, nil
|
||||
}
|
||||
|
@ -23,7 +23,9 @@ func TestRcloneExit(t *testing.T) {
|
||||
return
|
||||
}
|
||||
rtest.OK(t, err)
|
||||
defer be.Close()
|
||||
defer func() {
|
||||
rtest.OK(t, be.Close())
|
||||
}()
|
||||
|
||||
err = be.cmd.Process.Kill()
|
||||
rtest.OK(t, err)
|
||||
|
@ -327,7 +327,12 @@ func (c *Checker) Structure(ctx context.Context, p *progress.Counter, errChan ch
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
// the wait group should not return an error because no worker returns an
|
||||
// error, so panic if that has changed somehow.
|
||||
err := wg.Wait()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
|
||||
|
@ -79,7 +79,10 @@ func NewBackup(term *termstatus.Terminal, verbosity uint) *Backup {
|
||||
|
||||
func toJSONString(status interface{}) string {
|
||||
buf := new(bytes.Buffer)
|
||||
json.NewEncoder(buf).Encode(status)
|
||||
err := json.NewEncoder(buf).Encode(status)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -28,17 +28,23 @@ func buildTreeMap(tree TestTree, m TreeMap) restic.ID {
|
||||
for name, item := range tree {
|
||||
switch elem := item.(type) {
|
||||
case TestFile:
|
||||
res.Insert(&restic.Node{
|
||||
err := res.Insert(&restic.Node{
|
||||
Name: name,
|
||||
Type: "file",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
case TestTree:
|
||||
id := buildTreeMap(elem, m)
|
||||
res.Insert(&restic.Node{
|
||||
err := res.Insert(&restic.Node{
|
||||
Name: name,
|
||||
Subtree: &id,
|
||||
Type: "dir",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid type %T", elem))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user