diff options
author | Ben Kochie <superq@gmail.com> | 2020-06-15 22:27:14 +0200 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2020-06-16 14:47:03 +0200 |
commit | dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb (patch) | |
tree | 15025568f0d4c2ea666ad1c473ae97942eb6bfa1 /collector/textfile.go | |
parent | 3799895d414ef94822df11a80fe60565fc8bbd07 (diff) | |
download | prometheus_node_collector-dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb.tar.bz2 prometheus_node_collector-dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb.tar.xz prometheus_node_collector-dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb.zip |
Use Go 1.13 error features
* Use `errors.Is()` for unwrapping errors.
* Use `%w` error verb in internal error formatting.
Signed-off-by: Ben Kochie <superq@gmail.com>
Diffstat (limited to 'collector/textfile.go')
-rw-r--r-- | collector/textfile.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/collector/textfile.go b/collector/textfile.go index 64165e6..50c1807 100644 --- a/collector/textfile.go +++ b/collector/textfile.go | |||
@@ -238,14 +238,14 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric | |||
238 | path := filepath.Join(c.path, name) | 238 | path := filepath.Join(c.path, name) |
239 | f, err := os.Open(path) | 239 | f, err := os.Open(path) |
240 | if err != nil { | 240 | if err != nil { |
241 | return nil, fmt.Errorf("failed to open textfile data file %q: %v", path, err) | 241 | return nil, fmt.Errorf("failed to open textfile data file %q: %w", path, err) |
242 | } | 242 | } |
243 | defer f.Close() | 243 | defer f.Close() |
244 | 244 | ||
245 | var parser expfmt.TextParser | 245 | var parser expfmt.TextParser |
246 | families, err := parser.TextToMetricFamilies(f) | 246 | families, err := parser.TextToMetricFamilies(f) |
247 | if err != nil { | 247 | if err != nil { |
248 | return nil, fmt.Errorf("failed to parse textfile data from %q: %v", path, err) | 248 | return nil, fmt.Errorf("failed to parse textfile data from %q: %w", path, err) |
249 | } | 249 | } |
250 | 250 | ||
251 | if hasTimestamps(families) { | 251 | if hasTimestamps(families) { |
@@ -267,7 +267,7 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric | |||
267 | // a failure does not appear fresh. | 267 | // a failure does not appear fresh. |
268 | stat, err := f.Stat() | 268 | stat, err := f.Stat() |
269 | if err != nil { | 269 | if err != nil { |
270 | return nil, fmt.Errorf("failed to stat %q: %v", path, err) | 270 | return nil, fmt.Errorf("failed to stat %q: %w", path, err) |
271 | } | 271 | } |
272 | 272 | ||
273 | t := stat.ModTime() | 273 | t := stat.ModTime() |