1.2 KiB
1.2 KiB
Phase 2
Phase 2 is about error handling. We want to add some variants to DrawerError and a validate method to DrawerOperation
that will catch various problems and ensure that we can do the operation correctly. Here are some error cases in no particular order:
- If the command is
Openand the drawer file does not exist. - If the command is
Closeand the target path either does not exist, is not a directory, or is not readable. - If the
keyisEnvVarbut the$DRAWER_KEYenvironment variable is not set, or is not set to a path that exists and is readable. - If the
keyisPath()but the path does not exist or is not readable. - If the command is
Openand the target is a non-empty directory that exists, and theforceflag is false - If the command is
Closeand the target contains the drawer file (at any level; the target is any parent of the drawer file's path)
The validate method should take &self and return Result<(), DrawerError>. Let's have main, which is currently
creating a DrawerOperation and not using it, also call validate and print out the error if there is one. This means
we also need to impl Display on DrawerError.