cmd/lncli: return error upon missing channel backup when parsing

This commit is contained in:
Wilmer Paulino 2019-09-03 14:03:31 -07:00
parent 81cb3cb739
commit 06f544a78c
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -1567,12 +1567,12 @@ mnemonicCheck:
"RESTORE THE WALLET!!!")
// We'll also check to see if they provided any static channel backups,
// if so, then we'll also tack these onto the final innit wallet
// request.
// if so, then we'll also tack these onto the final init wallet request.
// We can ignore the errMissingChanBackup error as it's an optional
// field.
backups, err := parseChanBackups(ctx)
if err != nil {
return fmt.Errorf("unable to parse chan "+
"backups: %v", err)
if err != nil && err != errMissingChanBackup {
return fmt.Errorf("unable to parse chan backups: %v", err)
}
var chanBackups *lnrpc.ChanBackupSnapshot
@ -3931,6 +3931,10 @@ var restoreChanBackupCommand = cli.Command{
Action: actionDecorator(restoreChanBackup),
}
// errMissingChanBackup is an error returned when we attempt to parse a channel
// backup from a CLI command and it is missing.
var errMissingChanBackup = errors.New("missing channel backup")
func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error) {
switch {
case ctx.IsSet("single_backup"):
@ -3983,7 +3987,7 @@ func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error)
}, nil
default:
return nil, nil
return nil, errMissingChanBackup
}
}