Wrap errors so that they can be unwrapped

This commit is contained in:
Holger Obermaier
2026-02-11 13:51:58 +01:00
parent ca95494a83
commit 6bfdd6ff17
9 changed files with 35 additions and 42 deletions

View File

@@ -55,7 +55,7 @@ func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
const cpuInfoFile = "/proc/cpuinfo"
file, err := os.Open(cpuInfoFile)
if err != nil {
return fmt.Errorf("failed to open file '%s': %v", cpuInfoFile, err)
return fmt.Errorf("%s Init(): failed to open file '%s': %w", m.name, cpuInfoFile, err)
}
// Collect topology information from file cpuinfo
@@ -123,7 +123,7 @@ func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
// Check if at least one CPU with frequency information was detected
if len(m.topology) == 0 {
return fmt.Errorf("no CPU frequency info found in %s", cpuInfoFile)
return fmt.Errorf("%s Init(): no CPU frequency info found in %s", m.name, cpuInfoFile)
}
m.init = true