# Buggy code
def start(self, root):
    self.root = root
    logdir = expanduser(config.get("journaldir") or config.default_journal_dir)  # type: ignore # config is weird

    if not logdir or not isdir(logdir):  # type: ignore # config does weird things in its get
        self.stop()
        return False

    if self.currentdir and self.currentdir != logdir:
        self.stop()
    self.currentdir = logdir

    # Latest pre-existing logfile - e.g. if E:D is already running. Assumes logs sort alphabetically.
    # Do this before setting up the observer in case the journal directory has gone away
    try:
        logfiles = sorted(
            [
                x
                for x in listdir(self.currentdir)
                if re.search("^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$", x)
            ],
            key=lambda x: x.split(".")[1:],
        )
        self.logfile = logfiles and join(self.currentdir, logfiles[-1]) or None
    except:
        self.logfile = None
        return False

    # Set up a watchdog observer.
    # File system events are unreliable/non-existent over network drives on Linux.
    # We can't easily tell whether a path points to a network drive, so assume
    # any non-standard logdir might be on a network drive and poll instead.
    polling = bool(config.get("journaldir")) and platform != "win32"
    if not polling and not self.observer:
        self.observer = Observer()
        self.observer.daemon = True
        self.observer.start()
    elif polling and self.observer:
        self.observer.stop()
        self.observer = None

    if not self.observed and not polling:
        self.observed = self.observer.schedule(self, self.currentdir)

    if __debug__:
        print(
            '%s Journal "%s"' % (polling and "Polling" or "Monitoring", self.currentdir)
        )
        print('Start logfile "%s"' % self.logfile)

    if not self.running():
        self.thread = threading.Thread(target=self.worker, name="Journal worker")
        self.thread.daemon = True
        self.thread.start()

    return True


# Traceback (TypeError)
PS /home/[1000]/edmc> ./EDMarketConnector.py
loading plugin coriolis from "/home/chr0me/edmc/plugins/coriolis.py"
loading plugin eddb from "/home/chr0me/edmc/plugins/eddb.py"
loading plugin eddn from "/home/chr0me/edmc/plugins/eddn.py"
loading plugin edsm from "/home/chr0me/edmc/plugins/edsm.py"
loading plugin edsy from "/home/chr0me/edmc/plugins/edsy.py"
loading plugin inara from "/home/chr0me/edmc/plugins/inara.py"
Traceback (most recent call last):
File "/home/[1000]edmc/EDMarketConnector.py", line 947, in <module>
app = AppWindow(root)
File "/home/[1000]/edmc/EDMarketConnector.py", line 322, in __init__
self.postprefs(False)       # Companion login happens in callback from monitor
File "/home/[1000]/edmc/EDMarketConnector.py", line 339, in postprefs
if not monitor.start(self.w):
File "/home/[1000]/edmc/monitor.py", line 121, in start
logdir = expanduser(config.get('journaldir') or config.default_journal_dir)  # type: ignore # config is weird
File "/usr/lib/python3.8/posixpath.py", line 231, in expanduser
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

# Fixed code
def start(self, root):
    self.root = root
    journal_dir = config.get("journaldir") or config.default_journal_dir

    if journal_dir is None:
        journal_dir = ""

    # TODO(A_D): this is ignored for type checking due to all the different types config.get returns
    # When that is refactored, remove the magic comment
    logdir = expanduser(journal_dir)  # type: ignore # config is weird

    if not logdir or not isdir(logdir):
        self.stop()
        return False

    if self.currentdir and self.currentdir != logdir:
        self.stop()
    self.currentdir = logdir

    # Latest pre-existing logfile - e.g. if E:D is already running. Assumes logs sort alphabetically.
    # Do this before setting up the observer in case the journal directory has gone away
    try:
        logfiles = sorted(
            [
                x
                for x in listdir(self.currentdir)
                if re.search("^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$", x)
            ],
            key=lambda x: x.split(".")[1:],
        )
        self.logfile = logfiles and join(self.currentdir, logfiles[-1]) or None
    except:
        self.logfile = None
        return False

    # Set up a watchdog observer.
    # File system events are unreliable/non-existent over network drives on Linux.
    # We can't easily tell whether a path points to a network drive, so assume
    # any non-standard logdir might be on a network drive and poll instead.
    polling = bool(config.get("journaldir")) and platform != "win32"
    if not polling and not self.observer:
        self.observer = Observer()
        self.observer.daemon = True
        self.observer.start()
    elif polling and self.observer:
        self.observer.stop()
        self.observer = None

    if not self.observed and not polling:
        self.observed = self.observer.schedule(self, self.currentdir)

    if __debug__:
        print(
            '%s Journal "%s"' % (polling and "Polling" or "Monitoring", self.currentdir)
        )
        print('Start logfile "%s"' % self.logfile)

    if not self.running():
        self.thread = threading.Thread(target=self.worker, name="Journal worker")
        self.thread.daemon = True
        self.thread.start()

    return True