Skip to content

refactor: using fmt.Errorf in InfoWithContext #1840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"runtime"
"time"
Expand Down Expand Up @@ -70,47 +71,47 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {

ret.Hostname, err = os.Hostname()
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting hostname: %w", err)
}

ret.Platform, ret.PlatformFamily, ret.PlatformVersion, err = PlatformInformationWithContext(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting platform information: %w", err)
}

ret.KernelVersion, err = KernelVersionWithContext(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting kernel version: %w", err)
}

ret.KernelArch, err = KernelArch()
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting kernel archictecture: %w", err)
}

ret.VirtualizationSystem, ret.VirtualizationRole, err = VirtualizationWithContext(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting virtualization information: %w", err)
}

ret.BootTime, err = BootTimeWithContext(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting boot time: %w", err)
}

ret.Uptime, err = UptimeWithContext(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting uptime: %w", err)
}

ret.Procs, err = numProcs(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting number of procs: %w", err)
}

ret.HostID, err = HostIDWithContext(ctx)
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
return nil, err
return nil, fmt.Errorf("getting host ID: %w", err)
}

return ret, nil
Expand Down
Loading