Haskell error handling, log invalid file path to console -
as part of this project, i'd validate path of file that's provided passwords, i.e. pwds <- case cfgpasswords of passpath -> (map (just . t.unpack) . lines) <$> readfileutf8 passpath
, in case path file not valid i'd log message effect console.
how accomplish in haskell?
logf' "log level {}" [show loglevel] setloglevel loglevel debugf' "configuration: {}" [show cfg] ncpus <- getnumprocessors logf' "utilizing {} core(s)" [ncpus] setnumcapabilities ncpus pwds <- case cfgpasswords of passpath -> (map (just . t.unpack) . lines) <$> readfileutf8 passpath nothing -> return $ replicate (length cfgpublickeys) nothing when (length cfgpublickeys /= length cfgprivatekeys) $ errorl' "the same amount of public keys , private keys must specified" when (length cfgpublickeys /= length pwds) $ errorl' "the same amount of passwords must included in passwords file number of private keys. (if private key has no password, include blank line.)" when (cfgport == 0) $ errorl' "a listening port must specified 'port' in configuration file or --port @ runtime"
the idea go right above line when (length cfgpublickeys /= length cfgprivatekeys) $
.
i'm not sure have enough information in code snippet deduce precisely what's going on here type signatures.
the project you've linked seems it's written in go?
there appear number of project specific functions you're calling in code example.
for case of 'does file path point file,' you'd like:
checkforafile :: filepath -> io () checkforafile path = validfile <- doesfileexist path if validfile putstrln $ path ++ " file exists" else putstrln $ path ++ " not file exists"
doesfileexist
function available in system.directory
library, , canonical way answer question of whether or not filepath points file.
not knowing code doing, can't suggest proper place toss in check, that's enough go on.
if isn't, may suggest trying whet teeth on haskell code has little less going on.
wiki
Comments
Post a Comment