mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-07 11:06:36 +00:00
config: fix validation error with empty config files (#2080)
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -134,6 +135,11 @@ func NewConfigFileResolver(filePath string) (*Resolver, error) {
|
|||||||
decoder.KnownFields(true)
|
decoder.KnownFields(true)
|
||||||
|
|
||||||
if err = decoder.Decode(&configFileStructure); err != nil {
|
if err = decoder.Decode(&configFileStructure); err != nil {
|
||||||
|
// Handle EOF error gracefully, indicating no configuration was found.
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
return &Resolver{flags: flags}, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("configuration file validation error: %w", err)
|
return nil, fmt.Errorf("configuration file validation error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user