Merge pull request 'NoTorrcErr typed error' (#10) from notorrcerr into master

Reviewed-on: openprivacy/connectivity#10
This commit is contained in:
Sarah Jamie Lewis 2020-09-21 16:55:39 -07:00
commit d290b705eb
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