Skip to content

Commit

Permalink
include path in errors when reading bootstrap files
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Sep 24, 2021
1 parent 3e43c99 commit 8858d99
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,10 @@ func (fnb *FlowNodeBuilder) extraFlagsValidation() error {

// loadRootProtocolSnapshot loads the root protocol snapshot from disk
func loadRootProtocolSnapshot(dir string) (*inmem.Snapshot, error) {
data, err := io.ReadFile(filepath.Join(dir, bootstrap.PathRootProtocolStateSnapshot))
path := filepath.Join(dir, bootstrap.PathRootProtocolStateSnapshot)
data, err := io.ReadFile(path)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not read root snapshot (path=%s): %w", path, err)
}

var snapshot inmem.EncodableSnapshot
Expand All @@ -1071,9 +1072,10 @@ func loadRootProtocolSnapshot(dir string) (*inmem.Snapshot, error) {

// Loads the private info for this node from disk (eg. private staking/network keys).
func loadPrivateNodeInfo(dir string, myID flow.Identifier) (*bootstrap.NodeInfoPriv, error) {
data, err := io.ReadFile(filepath.Join(dir, fmt.Sprintf(bootstrap.PathNodeInfoPriv, myID)))
path := filepath.Join(dir, fmt.Sprintf(bootstrap.PathNodeInfoPriv, myID))
data, err := io.ReadFile(path)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not read private node info (path=%s): %w", path, err)
}
var info bootstrap.NodeInfoPriv
err = json.Unmarshal(data, &info)
Expand All @@ -1083,9 +1085,10 @@ func loadPrivateNodeInfo(dir string, myID flow.Identifier) (*bootstrap.NodeInfoP
// loadSecretsEncryptionKey loads the encryption key for the secrets database.
// If the file does not exist, returns os.ErrNotExist.
func loadSecretsEncryptionKey(dir string, myID flow.Identifier) ([]byte, error) {
data, err := io.ReadFile(filepath.Join(dir, fmt.Sprintf(bootstrap.PathSecretsEncryptionKey, myID)))
path := filepath.Join(dir, fmt.Sprintf(bootstrap.PathSecretsEncryptionKey, myID))
data, err := io.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("could not read key: %w", err)
return nil, fmt.Errorf("could not read secrets db encryption key (path=%s): %w", path, err)
}
return data, nil
}

0 comments on commit 8858d99

Please sign in to comment.