Merge pull request #3210 from nspcc-dev/service-err

wallet: provide more detailed errors on failed NewWalletFromFile
This commit is contained in:
Roman Khimov 2023-11-21 13:20:11 +03:00 committed by GitHub
commit 8e5a724f5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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