From 250b36eeb1a45f853f2dfde8c9567d21f699313d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 10 Oct 2016 20:55:02 +0200 Subject: [PATCH] Improve error message for 'forget' $ bin/restic forget /d 7 /w 4 /m 12 argument "/d" is not a snapshot ID, ignoring argument "7" is not a snapshot ID, ignoring argument "/w" is not a snapshot ID, ignoring argument "4" is not a snapshot ID, ignoring argument "/m" is not a snapshot ID, ignoring cound not find a snapshot for ID "12", ignoring --- src/cmds/restic/cmd_forget.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cmds/restic/cmd_forget.go b/src/cmds/restic/cmd_forget.go index 04e2d24e5..c2b8bacb6 100644 --- a/src/cmds/restic/cmd_forget.go +++ b/src/cmds/restic/cmd_forget.go @@ -1,6 +1,7 @@ package main import ( + "encoding/hex" "fmt" "io" "restic" @@ -116,11 +117,24 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error { return err } - // first, process all snapshot IDs given as arguments + // parse arguments as hex strings + var ids []string for _, s := range args { + _, err := hex.DecodeString(s) + if err != nil { + Warnf("argument %q is not a snapshot ID, ignoring\n", s) + continue + } + + ids = append(ids, s) + } + + // process all snapshot IDs given as arguments + for _, s := range ids { id, err := restic.FindSnapshot(repo, s) if err != nil { - return err + Warnf("cound not find a snapshot for ID %q, ignoring\n", s) + continue } if !opts.DryRun {