king: error message for lock file
@@ -6,14 +6,16 @@ module Urbit.Vere.LockFile (lockFile) where
import Urbit.Prelude
+import Urbit.King.App.Class
+
import Data.Default (def)
import RIO.Directory (createDirectoryIfMissing)
import System.IO.LockFile.Internal (LockingParameters(..), RetryStrategy(..),
- lock, unlock)
+ LockingException(..), lock, unlock)
--------------------------------------------------------------------------------
-lockFile :: HasLogFunc e => FilePath -> RAcquire e ()
+lockFile :: (HasLogFunc e, HasStderrLogFunc e) => FilePath -> RAcquire e ()
lockFile pax = void $ mkRAcquire start stop
where
fil = pax <> "/.vere.lock"
@@ -27,4 +29,19 @@ lockFile pax = void $ mkRAcquire start stop
start = do
createDirectoryIfMissing True pax
logInfo $ display @Text $ ("Taking lock file: " <> pack fil)
- io (lock params fil)
+ handle failure $ io (lock params fil)
+
+ failure (e :: LockingException) = do
+ logStderr $ logError $ display @Text $
+ "Cannot acquire lock file " <> pack fil <> "."
+ logStderr $ logError $
+ "Please make sure there are no other instances of this ship running, "
+ <> "then try again."
+ logStderr $ logError $
+ "If you are sure, you can delete the file and try again."
+ throwIO e
+
+logStderr :: HasStderrLogFunc e => RIO LogFunc a -> RIO e a
+logStderr action = do
+ logFunc <- view stderrLogFuncL
+ runRIO logFunc action
