diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 23b06b47f..6d00b1468 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -965,10 +965,13 @@ safeStrRead s = case reads s of -- XDG_DATA_HOME (or its default value), but for backwards compatibility, -- we fall back to the legacy user data directory ($HOME/.pandoc on *nix) -- if the XDG_DATA_HOME is missing and this exists. If neither directory --- is present, we return the XDG data directory. +-- is present, we return the XDG data directory. If the XDG data directory +-- is not defined (e.g. because we are in an environment where $HOME is +-- not defined), we return the empty string. defaultUserDataDir :: IO FilePath defaultUserDataDir = do - xdgDir <- getXdgDirectory XdgData "pandoc" + xdgDir <- E.catch (getXdgDirectory XdgData "pandoc") + (\(_ :: E.SomeException) -> return mempty) legacyDir <- getAppUserDataDirectory "pandoc" xdgExists <- doesDirectoryExist xdgDir legacyDirExists <- doesDirectoryExist legacyDir