I'm trying to figure out how to handle error if there are issues with directory permission and user is not able to walk into. as per os.walkDir I think it should raise OSError exception
iterator walkDir(dir: string; relative = false): tuple[kind: PathComponent, path: string] {.tags: [ReadDirEffect], raises: [OSError].}
I'm having scenario such as
OS : Linux & Mac
Dir : /tmp/abcd
case 1 : when abcd doesn't exist
case 2 : when abcd has permission error ( such as permission 000 ) ( user is not able to go inside as permission error)
My code looks like this
import os
var filepath="/tmp/abcd"
try :
for kind,path in walkDir(filepath) :
echo(kind,path)
except :
let
e = getCurrentException()
msg = getCurrentExceptionMsg()
echo("Got exception [", e.name, "] , message [", msg,"]")
in both above cases, I'm not getting any exception and code ending up with null output. I'm not sure how to validate if this is correct behaviour and how can I check this permission error.
Regards,