NoTorrcErr typed error

This commit is contained in:
Dan Ballard 2020-09-21 16:46:44 -07:00
parent 6f2a158504
commit f01a76f337
1 changed files with 10 additions and 2 deletions

View File

@ -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