From f01a76f337e9cb71fc87c978722391feb4c00492 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 21 Sep 2020 16:46:44 -0700 Subject: [PATCH] NoTorrcErr typed error --- tor/torProvider.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tor/torProvider.go b/tor/torProvider.go index 7b90396..33120f0 100644 --- a/tor/torProvider.go +++ b/tor/torProvider.go @@ -42,6 +42,13 @@ const ( networkUp = 0 ) +// NoTorrcError is a typed error thrown to indicate start could not complete due to lack of a torrc file +type NoTorrcError struct { + path string +} + +func (e *NoTorrcError) Error() string { return fmt.Sprintf("torrc file does not exist at %v", e.path) } + type onionListenService struct { os *tor.OnionService tp *torProvider @@ -286,8 +293,9 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe // check if the torrc file is present where expected if _, err := os.Stat(path.Join(dataDir, "torrc")); os.IsNotExist(err) { - log.Debugf("torrc file does not exist at %v", path.Join(dataDir, "torrc")) - return nil, fmt.Errorf("torrc file does not exist at %v", path.Join(dataDir, "torrc")) + err = &NoTorrcError{path.Join(dataDir, "torrc")} + log.Debugln(err.Error()) + return nil, err } // if not, try running system tor