From 8b7cef7f6148c3c7524c29c0f07add75a2df3e34 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Mon, 20 Feb 2023 10:05:04 -0500 Subject: [PATCH] Factor out some code into a helper function --- cmd/certspotter/main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/certspotter/main.go b/cmd/certspotter/main.go index 5266ba4..d873cdd 100644 --- a/cmd/certspotter/main.go +++ b/cmd/certspotter/main.go @@ -103,14 +103,19 @@ func defaultScriptDir() string { return filepath.Join(defaultConfigDir(), "hooks.d") } +func simplifyError(err error) error { + var pathErr *fs.PathError + if errors.As(err, &pathErr) { + return pathErr.Err + } + + return err +} + func readWatchListFile(filename string) (monitor.WatchList, error) { file, err := os.Open(filename) if err != nil { - var pathErr *fs.PathError - if errors.As(err, &pathErr) { - err = pathErr.Err - } - return nil, err + return nil, simplifyError(err) } defer file.Close() return monitor.ReadWatchList(file)