Skip to content

Commit 97e6597

Browse files
authored
wrap errors and fix some docs typo and convention (#743)
1 parent 394033d commit 97e6597

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

internal/pkg/agent/application/info/agent_id.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func getInfoFromStore(s ioStore, logLevel string) (*persistentAgentInfo, error)
7171
agentConfigFile := paths.AgentConfigFile()
7272
reader, err := s.Load()
7373
if err != nil {
74-
return nil, err
74+
return nil, fmt.Errorf("failed to load from ioStore: %w", err)
7575
}
7676

7777
// reader is closed by this function
@@ -195,20 +195,20 @@ func loadAgentInfo(forceUpdate bool, logLevel string, createAgentID bool) (*pers
195195
agentConfigFile := paths.AgentConfigFile()
196196
diskStore := storage.NewEncryptedDiskStore(agentConfigFile)
197197

198-
agentinfo, err := getInfoFromStore(diskStore, logLevel)
198+
agentInfo, err := getInfoFromStore(diskStore, logLevel)
199199
if err != nil {
200-
return nil, err
200+
return nil, fmt.Errorf("could not get agent info from store: %w", err)
201201
}
202202

203-
if agentinfo != nil && !forceUpdate && (agentinfo.ID != "" || !createAgentID) {
204-
return agentinfo, nil
203+
if agentInfo != nil && !forceUpdate && (agentInfo.ID != "" || !createAgentID) {
204+
return agentInfo, nil
205205
}
206206

207-
if err := updateID(agentinfo, diskStore); err != nil {
208-
return nil, err
207+
if err := updateID(agentInfo, diskStore); err != nil {
208+
return nil, fmt.Errorf("could not update agent ID on disk store: %w", err)
209209
}
210210

211-
return agentinfo, nil
211+
return agentInfo, nil
212212
}
213213

214214
func updateID(agentInfo *persistentAgentInfo, s ioStore) error {

internal/pkg/agent/application/info/agent_metadata.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"runtime"
1111
"strings"
1212

13-
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
14-
"github.com/elastic/elastic-agent/internal/pkg/release"
1513
"github.com/elastic/go-sysinfo"
1614
"github.com/elastic/go-sysinfo/types"
15+
16+
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
17+
"github.com/elastic/elastic-agent/internal/pkg/release"
1718
)
1819

1920
// ECSMeta is a collection of agent related metadata in ECS compliant object form.
@@ -123,7 +124,7 @@ const (
123124
func Metadata() (*ECSMeta, error) {
124125
agentInfo, err := NewAgentInfo(false)
125126
if err != nil {
126-
return nil, err
127+
return nil, fmt.Errorf("failed to create new agent info: %w", err)
127128
}
128129

129130
meta, err := agentInfo.ECSMetadata()

internal/pkg/agent/storage/encrypted_disk_store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hectane/go-acl"
1616

1717
"github.com/elastic/elastic-agent-libs/file"
18+
1819
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
1920
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
2021
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
@@ -78,7 +79,7 @@ func (d *EncryptedDiskStore) ensureKey() error {
7879
if d.key == nil {
7980
key, err := secret.GetAgentSecret(secret.WithVaultPath(d.vaultPath))
8081
if err != nil {
81-
return err
82+
return fmt.Errorf("could not get agent key: %w", err)
8283
}
8384
d.key = key.Value
8485
}

internal/pkg/agent/vault/vault_darwin.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ type Vault struct {
3737
}
3838

3939
// New initializes the vault store
40-
// Call Close when done to release the resouces
40+
// Call Close when done to release the resources
4141
func New(name string, opts ...OptionFunc) (*Vault, error) {
4242
var keychain C.SecKeychainRef
43+
4344
err := statusToError(C.OpenKeychain(keychain))
4445
if err != nil {
45-
return nil, err
46+
return nil, fmt.Errorf("could not open keychain: %w", err)
4647
}
48+
4749
return &Vault{
4850
name: name,
4951
keychain: keychain,

internal/pkg/agent/vault/vault_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func New(path string, opts ...OptionFunc) (v *Vault, err error) {
3939
if dir == "." {
4040
exefp, err := os.Executable()
4141
if err != nil {
42-
return nil, err
42+
return nil, fmt.Errorf("could not get executable path: %w", err)
4343
}
4444
dir = filepath.Dir(exefp)
4545
path = filepath.Join(dir, path)
@@ -62,7 +62,7 @@ func New(path string, opts ...OptionFunc) (v *Vault, err error) {
6262

6363
key, err := getOrCreateSeed(path, options.readonly)
6464
if err != nil {
65-
return nil, err
65+
return nil, fmt.Errorf("could not get seed to create new valt: %w", err)
6666
}
6767

6868
return &Vault{

0 commit comments

Comments
 (0)