wallet: provide more detailed errors on failed NewWalletFromFile

Close #3180.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-11-20 20:12:28 +03:00
parent f10d2d2be7
commit 59baecd39b

View file

@ -3,6 +3,7 @@ package wallet
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"os" "os"
@ -56,7 +57,7 @@ func NewWallet(location string) (*Wallet, error) {
func NewWalletFromFile(path string) (*Wallet, error) { func NewWalletFromFile(path string) (*Wallet, error) {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("open wallet: %w", err)
} }
defer file.Close() defer file.Close()
@ -64,7 +65,7 @@ func NewWalletFromFile(path string) (*Wallet, error) {
path: file.Name(), path: file.Name(),
} }
if err := json.NewDecoder(file).Decode(wall); err != nil { if err := json.NewDecoder(file).Decode(wall); err != nil {
return nil, err return nil, fmt.Errorf("unmarshal wallet: %w", err)
} }
return wall, nil return wall, nil
} }