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)
|
||||
|
||||
data AddrClass = IPv4AddrClass | IPv6AddrClass
|
||||
|
||||
data SomeAddr = IPv4Addr HostAddress
|
||||
{- My Android build of the Network library does not currently have IPV6
|
||||
- support. -}
|
||||
|
|
|
@ -33,9 +33,9 @@ pairingPort = 55556
|
|||
{- Goal: Reach all hosts on the same network segment.
|
||||
- Method: Use same address that avahi uses. Other broadcast addresses seem
|
||||
- to not be let through some routers. -}
|
||||
multicastAddress :: SomeAddr -> HostName
|
||||
multicastAddress (IPv4Addr _) = "224.0.0.251"
|
||||
multicastAddress (IPv6Addr _) = "ff02::fb"
|
||||
multicastAddress :: AddrClass -> HostName
|
||||
multicastAddress IPv4AddrClass = "224.0.0.251"
|
||||
multicastAddress IPv6AddrClass = "ff02::fb"
|
||||
|
||||
{- Multicasts a message repeatedly on all interfaces, with a 2 second
|
||||
- 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 $
|
||||
withSocketsDo $ bracket setup cleanup use
|
||||
where
|
||||
setup = multicastSender (multicastAddress i) pairingPort
|
||||
setup = multicastSender (multicastAddress IPv4AddrClass) pairingPort
|
||||
cleanup (sock, _) = sClose sock -- FIXME does not work
|
||||
use (sock, addr) = do
|
||||
setInterface sock (showAddr i)
|
||||
|
|
|
@ -196,7 +196,7 @@ maxCommitSize :: Int
|
|||
maxCommitSize = 5000
|
||||
|
||||
{- 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,
|
||||
- a batch activity is taking place, so wait for later.
|
||||
|
|
|
@ -31,7 +31,7 @@ pairListenerThread urlrenderer = namedThread "PairListener" $ do
|
|||
where
|
||||
{- Note this can crash if there's no network interface,
|
||||
- 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
|
||||
Nothing -> go reqs cache sock
|
||||
|
|
|
@ -78,4 +78,5 @@ selectNextPush lastpushedto l = go [] l
|
|||
(Pushing clientid _)
|
||||
| Just clientid /= lastpushedto -> (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
|
||||
checkEnvironmentIO
|
||||
{- 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
|
||||
- threadstate. -}
|
||||
let st = undefined
|
||||
let st = error "annex state not available"
|
||||
{- Get a DaemonStatus without running in the Annex monad. -}
|
||||
dstatus <- atomically . newTMVar =<< newDaemonStatus
|
||||
d <- newAssistantData st dstatus
|
||||
|
|
|
@ -93,7 +93,7 @@ genSharedCipher highQuality =
|
|||
{- Updates an existing Cipher, re-encrypting it to add or remove keyids,
|
||||
- depending on whether the first component is True or False. -}
|
||||
updateEncryptedCipher :: [(Bool, String)] -> StorableCipher -> IO StorableCipher
|
||||
updateEncryptedCipher _ SharedCipher{} = undefined
|
||||
updateEncryptedCipher _ SharedCipher{} = error "Cannot update shared cipher"
|
||||
updateEncryptedCipher [] encipher = return encipher
|
||||
updateEncryptedCipher newkeys encipher@(EncryptedCipher _ variant (KeyIds ks)) = do
|
||||
dropKeys <- listKeyIds [ k | (False, k) <- newkeys ]
|
||||
|
|
|
@ -55,7 +55,7 @@ Fscked
|
|||
-
|
||||
- This may fail, if other fsck processes are currently running using the
|
||||
- database. Removing the database in that situation would lead to crashes
|
||||
- or undefined behavior.
|
||||
- or unknown behavior.
|
||||
-}
|
||||
newPass :: UUID -> Annex Bool
|
||||
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 { gitdir = 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,
|
||||
- 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 { gitdir = d } } = d
|
||||
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. -}
|
||||
localGitDir :: Repo -> FilePath
|
||||
localGitDir Repo { location = Local { gitdir = d } } = d
|
||||
localGitDir _ = undefined
|
||||
localGitDir _ = error "unknown localGitDir"
|
||||
|
||||
{- Some code needs to vary between URL and normal repos,
|
||||
- or bare and non-bare, these functions help with that. -}
|
||||
|
|
|
@ -110,4 +110,4 @@ catTree h treeref = go <$> catObjectDetails h treeref
|
|||
parsemodefile b =
|
||||
let (modestr, file) = separate (== ' ') (decodeBS b)
|
||||
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
|
||||
(rawblobtype:rawsha:rawstage:_) -> do
|
||||
stage <- readish rawstage :: Maybe Int
|
||||
unless (stage == 2 || stage == 3) $
|
||||
fail undefined -- skip stage 1
|
||||
blobtype <- readBlobType rawblobtype
|
||||
sha <- extractSha rawsha
|
||||
return $ InternalUnmerged (stage == 2) file
|
||||
(Just blobtype) (Just sha)
|
||||
if stage /= 2 && stage /= 3
|
||||
then Nothing
|
||||
else do
|
||||
blobtype <- readBlobType rawblobtype
|
||||
sha <- extractSha rawsha
|
||||
return $ InternalUnmerged (stage == 2) file
|
||||
(Just blobtype) (Just sha)
|
||||
_ -> Nothing
|
||||
where
|
||||
(metadata, file) = separate (== '\t') s
|
||||
|
|
|
@ -397,7 +397,7 @@ getGCryptId fast r gc
|
|||
| Git.repoIsLocal r || Git.repoIsLocalUnknown r = extract <$>
|
||||
liftIO (catchMaybeIO $ Git.Config.read r)
|
||||
| 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
|
||||
]
|
||||
| otherwise = return (Nothing, r)
|
||||
|
|
|
@ -199,7 +199,7 @@ tryGitConfigRead :: Git.Repo -> Annex Git.Repo
|
|||
tryGitConfigRead r
|
||||
| haveconfig r = return r -- already read
|
||||
| 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
|
||||
Right r'
|
||||
| haveconfig r' -> return r'
|
||||
|
@ -228,9 +228,10 @@ tryGitConfigRead r
|
|||
uo <- Url.getUrlOptions
|
||||
v <- liftIO $ withTmpFile "git-annex.tmp" $ \tmpfile h -> do
|
||||
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]
|
||||
, return $ Left undefined
|
||||
, return $ Left $ error $ "unable to load config from " ++ url
|
||||
)
|
||||
case v of
|
||||
Left _ -> do
|
||||
|
|
|
@ -72,7 +72,7 @@ chunkKeyStream basek chunksize = ChunkKeyStream $ map mk [1..]
|
|||
|
||||
nextChunkKeyStream :: ChunkKeyStream -> (Key, ChunkKeyStream)
|
||||
nextChunkKeyStream (ChunkKeyStream (k:l)) = (k, ChunkKeyStream l)
|
||||
nextChunkKeyStream (ChunkKeyStream []) = undefined -- stream is infinite!
|
||||
nextChunkKeyStream (ChunkKeyStream []) = error "expected infinite ChunkKeyStream"
|
||||
|
||||
takeChunkKeyStream :: ChunkCount -> ChunkKeyStream -> [Key]
|
||||
takeChunkKeyStream n (ChunkKeyStream l) = genericTake n l
|
||||
|
|
|
@ -57,7 +57,7 @@ eventsCoalesce = False
|
|||
#if (WITH_KQUEUE || WITH_FSEVENTS)
|
||||
eventsCoalesce = True
|
||||
#else
|
||||
eventsCoalesce = undefined
|
||||
eventsCoalesce = error "eventsCoalesce not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -78,7 +78,7 @@ closingTracked = True
|
|||
#if WITH_KQUEUE
|
||||
closingTracked = False
|
||||
#else
|
||||
closingTracked = undefined
|
||||
closingTracked = error "closingTracked not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -93,7 +93,7 @@ modifyTracked = True
|
|||
#if WITH_KQUEUE
|
||||
modifyTracked = False
|
||||
#else
|
||||
modifyTracked = undefined
|
||||
modifyTracked = error "modifyTracked not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -131,7 +131,7 @@ watchDir dir prune scanevents hooks runstartup =
|
|||
#else
|
||||
type DirWatcherHandle = ()
|
||||
watchDir :: FilePath -> Pruner -> Bool -> WatchHooks -> (IO () -> IO ()) -> IO DirWatcherHandle
|
||||
watchDir = undefined
|
||||
watchDir = error "watchDir not defined"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
@ -150,7 +150,7 @@ stopWatchDir = FSEvents.eventStreamDestroy
|
|||
#if WITH_WIN32NOTIFY
|
||||
stopWatchDir = Win32Notify.killWatchManager
|
||||
#else
|
||||
stopWatchDir = undefined
|
||||
stopWatchDir = error "stopWatchDir not defined"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -111,7 +111,7 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
|
|||
-- But, mv will move into a directory if
|
||||
-- dest is one, which is not desired.
|
||||
whenM (isdir dest) rethrow
|
||||
viaTmp mv dest undefined
|
||||
viaTmp mv dest ""
|
||||
where
|
||||
rethrow = throwM e
|
||||
mv tmp _ = do
|
||||
|
|
|
@ -124,7 +124,7 @@ withUmask _ a = a
|
|||
#endif
|
||||
|
||||
combineModes :: [FileMode] -> FileMode
|
||||
combineModes [] = undefined
|
||||
combineModes [] = 0
|
||||
combineModes [m] = m
|
||||
combineModes (m:ms) = foldl unionFileModes m ms
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ defaultChunkSize :: Int
|
|||
defaultChunkSize = 32 * k - chunkOverhead
|
||||
where
|
||||
k = 1024
|
||||
chunkOverhead = 2 * sizeOf (undefined :: Int) -- GHC specific
|
||||
chunkOverhead = 2 * sizeOf (1 :: Int) -- GHC specific
|
||||
|
||||
data OutputHandler = OutputHandler
|
||||
{ quietMode :: Bool
|
||||
|
|
|
@ -54,8 +54,8 @@ instance Storable TimeSpec where
|
|||
-- use the larger alignment of the two types in the struct
|
||||
alignment _ = max sec_alignment nsec_alignment
|
||||
where
|
||||
sec_alignment = alignment (undefined::CTime)
|
||||
nsec_alignment = alignment (undefined::CLong)
|
||||
sec_alignment = alignment (1::CTime)
|
||||
nsec_alignment = alignment (1::CLong)
|
||||
sizeOf _ = #{size struct timespec}
|
||||
peek ptr = do
|
||||
sec <- #{peek struct timespec, tv_sec} ptr
|
||||
|
@ -92,7 +92,7 @@ touchBoth file atime mtime follow =
|
|||
-}
|
||||
|
||||
instance Storable TimeSpec where
|
||||
alignment _ = alignment (undefined::CLong)
|
||||
alignment _ = alignment (1::CLong)
|
||||
sizeOf _ = #{size struct timeval}
|
||||
peek ptr = do
|
||||
sec <- #{peek struct timeval, tv_sec} ptr
|
||||
|
|
Loading…
Reference in a new issue