removed all uses of undefined from code base
It's a code smell, can lead to hard to diagnose error messages.
This commit is contained in:
parent
d7f4c823d7
commit
addc82dab7
19 changed files with 42 additions and 37 deletions
|
@ -81,6 +81,8 @@ data PairingInProgress = PairingInProgress
|
||||||
}
|
}
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
data AddrClass = IPv4AddrClass | IPv6AddrClass
|
||||||
|
|
||||||
data SomeAddr = IPv4Addr HostAddress
|
data SomeAddr = IPv4Addr HostAddress
|
||||||
{- My Android build of the Network library does not currently have IPV6
|
{- My Android build of the Network library does not currently have IPV6
|
||||||
- support. -}
|
- support. -}
|
||||||
|
|
|
@ -33,9 +33,9 @@ pairingPort = 55556
|
||||||
{- Goal: Reach all hosts on the same network segment.
|
{- Goal: Reach all hosts on the same network segment.
|
||||||
- Method: Use same address that avahi uses. Other broadcast addresses seem
|
- Method: Use same address that avahi uses. Other broadcast addresses seem
|
||||||
- to not be let through some routers. -}
|
- to not be let through some routers. -}
|
||||||
multicastAddress :: SomeAddr -> HostName
|
multicastAddress :: AddrClass -> HostName
|
||||||
multicastAddress (IPv4Addr _) = "224.0.0.251"
|
multicastAddress IPv4AddrClass = "224.0.0.251"
|
||||||
multicastAddress (IPv6Addr _) = "ff02::fb"
|
multicastAddress IPv6AddrClass = "ff02::fb"
|
||||||
|
|
||||||
{- Multicasts a message repeatedly on all interfaces, with a 2 second
|
{- Multicasts a message repeatedly on all interfaces, with a 2 second
|
||||||
- delay between each transmission. The message is repeated forever
|
- delay between each transmission. The message is repeated forever
|
||||||
|
@ -62,7 +62,7 @@ multicastPairMsg repeats secret pairdata stage = go M.empty repeats
|
||||||
sendinterface cache i = void $ tryIO $
|
sendinterface cache i = void $ tryIO $
|
||||||
withSocketsDo $ bracket setup cleanup use
|
withSocketsDo $ bracket setup cleanup use
|
||||||
where
|
where
|
||||||
setup = multicastSender (multicastAddress i) pairingPort
|
setup = multicastSender (multicastAddress IPv4AddrClass) pairingPort
|
||||||
cleanup (sock, _) = sClose sock -- FIXME does not work
|
cleanup (sock, _) = sClose sock -- FIXME does not work
|
||||||
use (sock, addr) = do
|
use (sock, addr) = do
|
||||||
setInterface sock (showAddr i)
|
setInterface sock (showAddr i)
|
||||||
|
|
|
@ -196,7 +196,7 @@ maxCommitSize :: Int
|
||||||
maxCommitSize = 5000
|
maxCommitSize = 5000
|
||||||
|
|
||||||
{- Decide if now is a good time to make a commit.
|
{- Decide if now is a good time to make a commit.
|
||||||
- Note that the list of changes has an undefined order.
|
- Note that the list of changes has a random order.
|
||||||
-
|
-
|
||||||
- Current strategy: If there have been 10 changes within the past second,
|
- Current strategy: If there have been 10 changes within the past second,
|
||||||
- a batch activity is taking place, so wait for later.
|
- a batch activity is taking place, so wait for later.
|
||||||
|
|
|
@ -31,7 +31,7 @@ pairListenerThread urlrenderer = namedThread "PairListener" $ do
|
||||||
where
|
where
|
||||||
{- Note this can crash if there's no network interface,
|
{- Note this can crash if there's no network interface,
|
||||||
- or only one like lo that doesn't support multicast. -}
|
- or only one like lo that doesn't support multicast. -}
|
||||||
getsock = multicastReceiver (multicastAddress $ IPv4Addr undefined) pairingPort
|
getsock = multicastReceiver (multicastAddress IPv4AddrClass) pairingPort
|
||||||
|
|
||||||
go reqs cache sock = liftIO (getmsg sock []) >>= \msg -> case readish msg of
|
go reqs cache sock = liftIO (getmsg sock []) >>= \msg -> case readish msg of
|
||||||
Nothing -> go reqs cache sock
|
Nothing -> go reqs cache sock
|
||||||
|
|
|
@ -78,4 +78,5 @@ selectNextPush lastpushedto l = go [] l
|
||||||
(Pushing clientid _)
|
(Pushing clientid _)
|
||||||
| Just clientid /= lastpushedto -> (m, rejected ++ ms)
|
| Just clientid /= lastpushedto -> (m, rejected ++ ms)
|
||||||
_ -> go (m:rejected) ms
|
_ -> go (m:rejected) ms
|
||||||
go [] [] = undefined
|
go [] [] = error "empty push queue"
|
||||||
|
|
||||||
|
|
|
@ -143,10 +143,10 @@ firstRun :: Maybe HostName -> IO ()
|
||||||
firstRun listenhost = do
|
firstRun listenhost = do
|
||||||
checkEnvironmentIO
|
checkEnvironmentIO
|
||||||
{- Without a repository, we cannot have an Annex monad, so cannot
|
{- Without a repository, we cannot have an Annex monad, so cannot
|
||||||
- get a ThreadState. Using undefined is only safe because the
|
- get a ThreadState. This is only safe because the
|
||||||
- webapp checks its noAnnex field before accessing the
|
- webapp checks its noAnnex field before accessing the
|
||||||
- threadstate. -}
|
- threadstate. -}
|
||||||
let st = undefined
|
let st = error "annex state not available"
|
||||||
{- Get a DaemonStatus without running in the Annex monad. -}
|
{- Get a DaemonStatus without running in the Annex monad. -}
|
||||||
dstatus <- atomically . newTMVar =<< newDaemonStatus
|
dstatus <- atomically . newTMVar =<< newDaemonStatus
|
||||||
d <- newAssistantData st dstatus
|
d <- newAssistantData st dstatus
|
||||||
|
|
|
@ -93,7 +93,7 @@ genSharedCipher highQuality =
|
||||||
{- Updates an existing Cipher, re-encrypting it to add or remove keyids,
|
{- Updates an existing Cipher, re-encrypting it to add or remove keyids,
|
||||||
- depending on whether the first component is True or False. -}
|
- depending on whether the first component is True or False. -}
|
||||||
updateEncryptedCipher :: [(Bool, String)] -> StorableCipher -> IO StorableCipher
|
updateEncryptedCipher :: [(Bool, String)] -> StorableCipher -> IO StorableCipher
|
||||||
updateEncryptedCipher _ SharedCipher{} = undefined
|
updateEncryptedCipher _ SharedCipher{} = error "Cannot update shared cipher"
|
||||||
updateEncryptedCipher [] encipher = return encipher
|
updateEncryptedCipher [] encipher = return encipher
|
||||||
updateEncryptedCipher newkeys encipher@(EncryptedCipher _ variant (KeyIds ks)) = do
|
updateEncryptedCipher newkeys encipher@(EncryptedCipher _ variant (KeyIds ks)) = do
|
||||||
dropKeys <- listKeyIds [ k | (False, k) <- newkeys ]
|
dropKeys <- listKeyIds [ k | (False, k) <- newkeys ]
|
||||||
|
|
|
@ -55,7 +55,7 @@ Fscked
|
||||||
-
|
-
|
||||||
- This may fail, if other fsck processes are currently running using the
|
- This may fail, if other fsck processes are currently running using the
|
||||||
- database. Removing the database in that situation would lead to crashes
|
- database. Removing the database in that situation would lead to crashes
|
||||||
- or undefined behavior.
|
- or unknown behavior.
|
||||||
-}
|
-}
|
||||||
newPass :: UUID -> Annex Bool
|
newPass :: UUID -> Annex Bool
|
||||||
newPass u = isJust <$> tryExclusiveLock (gitAnnexFsckDbLock u) go
|
newPass u = isJust <$> tryExclusiveLock (gitAnnexFsckDbLock u) go
|
||||||
|
|
6
Git.hs
6
Git.hs
|
@ -60,7 +60,7 @@ repoLocation Repo { location = Url url } = show url
|
||||||
repoLocation Repo { location = Local { worktree = Just dir } } = dir
|
repoLocation Repo { location = Local { worktree = Just dir } } = dir
|
||||||
repoLocation Repo { location = Local { gitdir = dir } } = dir
|
repoLocation Repo { location = Local { gitdir = dir } } = dir
|
||||||
repoLocation Repo { location = LocalUnknown dir } = dir
|
repoLocation Repo { location = LocalUnknown dir } = dir
|
||||||
repoLocation Repo { location = Unknown } = undefined
|
repoLocation Repo { location = Unknown } = error "unknown repoLocation"
|
||||||
|
|
||||||
{- Path to a repository. For non-bare, this is the worktree, for bare,
|
{- Path to a repository. For non-bare, this is the worktree, for bare,
|
||||||
- it's the gitdir, and for URL repositories, is the path on the remote
|
- it's the gitdir, and for URL repositories, is the path on the remote
|
||||||
|
@ -70,12 +70,12 @@ repoPath Repo { location = Url u } = unEscapeString $ uriPath u
|
||||||
repoPath Repo { location = Local { worktree = Just d } } = d
|
repoPath Repo { location = Local { worktree = Just d } } = d
|
||||||
repoPath Repo { location = Local { gitdir = d } } = d
|
repoPath Repo { location = Local { gitdir = d } } = d
|
||||||
repoPath Repo { location = LocalUnknown dir } = dir
|
repoPath Repo { location = LocalUnknown dir } = dir
|
||||||
repoPath Repo { location = Unknown } = undefined
|
repoPath Repo { location = Unknown } = error "unknown repoPath"
|
||||||
|
|
||||||
{- Path to a local repository's .git directory. -}
|
{- Path to a local repository's .git directory. -}
|
||||||
localGitDir :: Repo -> FilePath
|
localGitDir :: Repo -> FilePath
|
||||||
localGitDir Repo { location = Local { gitdir = d } } = d
|
localGitDir Repo { location = Local { gitdir = d } } = d
|
||||||
localGitDir _ = undefined
|
localGitDir _ = error "unknown localGitDir"
|
||||||
|
|
||||||
{- Some code needs to vary between URL and normal repos,
|
{- Some code needs to vary between URL and normal repos,
|
||||||
- or bare and non-bare, these functions help with that. -}
|
- or bare and non-bare, these functions help with that. -}
|
||||||
|
|
|
@ -110,4 +110,4 @@ catTree h treeref = go <$> catObjectDetails h treeref
|
||||||
parsemodefile b =
|
parsemodefile b =
|
||||||
let (modestr, file) = separate (== ' ') (decodeBS b)
|
let (modestr, file) = separate (== ' ') (decodeBS b)
|
||||||
in (file, readmode modestr)
|
in (file, readmode modestr)
|
||||||
readmode = fst . fromMaybe (0, undefined) . headMaybe . readOct
|
readmode = fromMaybe 0 . fmap fst . headMaybe . readOct
|
||||||
|
|
|
@ -181,12 +181,13 @@ parseUnmerged s
|
||||||
| otherwise = case words metadata of
|
| otherwise = case words metadata of
|
||||||
(rawblobtype:rawsha:rawstage:_) -> do
|
(rawblobtype:rawsha:rawstage:_) -> do
|
||||||
stage <- readish rawstage :: Maybe Int
|
stage <- readish rawstage :: Maybe Int
|
||||||
unless (stage == 2 || stage == 3) $
|
if stage /= 2 && stage /= 3
|
||||||
fail undefined -- skip stage 1
|
then Nothing
|
||||||
blobtype <- readBlobType rawblobtype
|
else do
|
||||||
sha <- extractSha rawsha
|
blobtype <- readBlobType rawblobtype
|
||||||
return $ InternalUnmerged (stage == 2) file
|
sha <- extractSha rawsha
|
||||||
(Just blobtype) (Just sha)
|
return $ InternalUnmerged (stage == 2) file
|
||||||
|
(Just blobtype) (Just sha)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
where
|
where
|
||||||
(metadata, file) = separate (== '\t') s
|
(metadata, file) = separate (== '\t') s
|
||||||
|
|
|
@ -397,7 +397,7 @@ getGCryptId fast r gc
|
||||||
| Git.repoIsLocal r || Git.repoIsLocalUnknown r = extract <$>
|
| Git.repoIsLocal r || Git.repoIsLocalUnknown r = extract <$>
|
||||||
liftIO (catchMaybeIO $ Git.Config.read r)
|
liftIO (catchMaybeIO $ Git.Config.read r)
|
||||||
| not fast = extract . liftM fst <$> getM (eitherToMaybe <$>)
|
| not fast = extract . liftM fst <$> getM (eitherToMaybe <$>)
|
||||||
[ Ssh.onRemote r (Git.Config.fromPipe r, return (Left undefined)) "configlist" [] []
|
[ Ssh.onRemote r (Git.Config.fromPipe r, return (Left $ error "configlist failed")) "configlist" [] []
|
||||||
, getConfigViaRsync r gc
|
, getConfigViaRsync r gc
|
||||||
]
|
]
|
||||||
| otherwise = return (Nothing, r)
|
| otherwise = return (Nothing, r)
|
||||||
|
|
|
@ -199,7 +199,7 @@ tryGitConfigRead :: Git.Repo -> Annex Git.Repo
|
||||||
tryGitConfigRead r
|
tryGitConfigRead r
|
||||||
| haveconfig r = return r -- already read
|
| haveconfig r = return r -- already read
|
||||||
| Git.repoIsSsh r = store $ do
|
| Git.repoIsSsh r = store $ do
|
||||||
v <- Ssh.onRemote r (pipedconfig, return (Left undefined)) "configlist" [] []
|
v <- Ssh.onRemote r (pipedconfig, return (Left $ error "configlist failed")) "configlist" [] []
|
||||||
case v of
|
case v of
|
||||||
Right r'
|
Right r'
|
||||||
| haveconfig r' -> return r'
|
| haveconfig r' -> return r'
|
||||||
|
@ -228,9 +228,10 @@ tryGitConfigRead r
|
||||||
uo <- Url.getUrlOptions
|
uo <- Url.getUrlOptions
|
||||||
v <- liftIO $ withTmpFile "git-annex.tmp" $ \tmpfile h -> do
|
v <- liftIO $ withTmpFile "git-annex.tmp" $ \tmpfile h -> do
|
||||||
hClose h
|
hClose h
|
||||||
ifM (Url.downloadQuiet (Git.repoLocation r ++ "/config") tmpfile uo)
|
let url = Git.repoLocation r ++ "/config"
|
||||||
|
ifM (Url.downloadQuiet url tmpfile uo)
|
||||||
( pipedconfig "git" [Param "config", Param "--null", Param "--list", Param "--file", File tmpfile]
|
( pipedconfig "git" [Param "config", Param "--null", Param "--list", Param "--file", File tmpfile]
|
||||||
, return $ Left undefined
|
, return $ Left $ error $ "unable to load config from " ++ url
|
||||||
)
|
)
|
||||||
case v of
|
case v of
|
||||||
Left _ -> do
|
Left _ -> do
|
||||||
|
|
|
@ -72,7 +72,7 @@ chunkKeyStream basek chunksize = ChunkKeyStream $ map mk [1..]
|
||||||
|
|
||||||
nextChunkKeyStream :: ChunkKeyStream -> (Key, ChunkKeyStream)
|
nextChunkKeyStream :: ChunkKeyStream -> (Key, ChunkKeyStream)
|
||||||
nextChunkKeyStream (ChunkKeyStream (k:l)) = (k, ChunkKeyStream l)
|
nextChunkKeyStream (ChunkKeyStream (k:l)) = (k, ChunkKeyStream l)
|
||||||
nextChunkKeyStream (ChunkKeyStream []) = undefined -- stream is infinite!
|
nextChunkKeyStream (ChunkKeyStream []) = error "expected infinite ChunkKeyStream"
|
||||||
|
|
||||||
takeChunkKeyStream :: ChunkCount -> ChunkKeyStream -> [Key]
|
takeChunkKeyStream :: ChunkCount -> ChunkKeyStream -> [Key]
|
||||||
takeChunkKeyStream n (ChunkKeyStream l) = genericTake n l
|
takeChunkKeyStream n (ChunkKeyStream l) = genericTake n l
|
||||||
|
|
|
@ -57,7 +57,7 @@ eventsCoalesce = False
|
||||||
#if (WITH_KQUEUE || WITH_FSEVENTS)
|
#if (WITH_KQUEUE || WITH_FSEVENTS)
|
||||||
eventsCoalesce = True
|
eventsCoalesce = True
|
||||||
#else
|
#else
|
||||||
eventsCoalesce = undefined
|
eventsCoalesce = error "eventsCoalesce not defined"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ closingTracked = True
|
||||||
#if WITH_KQUEUE
|
#if WITH_KQUEUE
|
||||||
closingTracked = False
|
closingTracked = False
|
||||||
#else
|
#else
|
||||||
closingTracked = undefined
|
closingTracked = error "closingTracked not defined"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ modifyTracked = True
|
||||||
#if WITH_KQUEUE
|
#if WITH_KQUEUE
|
||||||
modifyTracked = False
|
modifyTracked = False
|
||||||
#else
|
#else
|
||||||
modifyTracked = undefined
|
modifyTracked = error "modifyTracked not defined"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ watchDir dir prune scanevents hooks runstartup =
|
||||||
#else
|
#else
|
||||||
type DirWatcherHandle = ()
|
type DirWatcherHandle = ()
|
||||||
watchDir :: FilePath -> Pruner -> Bool -> WatchHooks -> (IO () -> IO ()) -> IO DirWatcherHandle
|
watchDir :: FilePath -> Pruner -> Bool -> WatchHooks -> (IO () -> IO ()) -> IO DirWatcherHandle
|
||||||
watchDir = undefined
|
watchDir = error "watchDir not defined"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -150,7 +150,7 @@ stopWatchDir = FSEvents.eventStreamDestroy
|
||||||
#if WITH_WIN32NOTIFY
|
#if WITH_WIN32NOTIFY
|
||||||
stopWatchDir = Win32Notify.killWatchManager
|
stopWatchDir = Win32Notify.killWatchManager
|
||||||
#else
|
#else
|
||||||
stopWatchDir = undefined
|
stopWatchDir = error "stopWatchDir not defined"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,7 +111,7 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
|
||||||
-- But, mv will move into a directory if
|
-- But, mv will move into a directory if
|
||||||
-- dest is one, which is not desired.
|
-- dest is one, which is not desired.
|
||||||
whenM (isdir dest) rethrow
|
whenM (isdir dest) rethrow
|
||||||
viaTmp mv dest undefined
|
viaTmp mv dest ""
|
||||||
where
|
where
|
||||||
rethrow = throwM e
|
rethrow = throwM e
|
||||||
mv tmp _ = do
|
mv tmp _ = do
|
||||||
|
|
|
@ -124,7 +124,7 @@ withUmask _ a = a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
combineModes :: [FileMode] -> FileMode
|
combineModes :: [FileMode] -> FileMode
|
||||||
combineModes [] = undefined
|
combineModes [] = 0
|
||||||
combineModes [m] = m
|
combineModes [m] = m
|
||||||
combineModes (m:ms) = foldl unionFileModes m ms
|
combineModes (m:ms) = foldl unionFileModes m ms
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ defaultChunkSize :: Int
|
||||||
defaultChunkSize = 32 * k - chunkOverhead
|
defaultChunkSize = 32 * k - chunkOverhead
|
||||||
where
|
where
|
||||||
k = 1024
|
k = 1024
|
||||||
chunkOverhead = 2 * sizeOf (undefined :: Int) -- GHC specific
|
chunkOverhead = 2 * sizeOf (1 :: Int) -- GHC specific
|
||||||
|
|
||||||
data OutputHandler = OutputHandler
|
data OutputHandler = OutputHandler
|
||||||
{ quietMode :: Bool
|
{ quietMode :: Bool
|
||||||
|
|
|
@ -54,8 +54,8 @@ instance Storable TimeSpec where
|
||||||
-- use the larger alignment of the two types in the struct
|
-- use the larger alignment of the two types in the struct
|
||||||
alignment _ = max sec_alignment nsec_alignment
|
alignment _ = max sec_alignment nsec_alignment
|
||||||
where
|
where
|
||||||
sec_alignment = alignment (undefined::CTime)
|
sec_alignment = alignment (1::CTime)
|
||||||
nsec_alignment = alignment (undefined::CLong)
|
nsec_alignment = alignment (1::CLong)
|
||||||
sizeOf _ = #{size struct timespec}
|
sizeOf _ = #{size struct timespec}
|
||||||
peek ptr = do
|
peek ptr = do
|
||||||
sec <- #{peek struct timespec, tv_sec} ptr
|
sec <- #{peek struct timespec, tv_sec} ptr
|
||||||
|
@ -92,7 +92,7 @@ touchBoth file atime mtime follow =
|
||||||
-}
|
-}
|
||||||
|
|
||||||
instance Storable TimeSpec where
|
instance Storable TimeSpec where
|
||||||
alignment _ = alignment (undefined::CLong)
|
alignment _ = alignment (1::CLong)
|
||||||
sizeOf _ = #{size struct timeval}
|
sizeOf _ = #{size struct timeval}
|
||||||
peek ptr = do
|
peek ptr = do
|
||||||
sec <- #{peek struct timeval, tv_sec} ptr
|
sec <- #{peek struct timeval, tv_sec} ptr
|
||||||
|
|
Loading…
Reference in a new issue