Better error handling for list dir and cli
This commit is contained in:
+17
-3
@@ -5,12 +5,26 @@ import "core:os"
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
get_working_dir :: proc(allocator := context.allocator) -> string {
|
||||
Error :: union #shared_nil {
|
||||
os.Error,
|
||||
File_Error,
|
||||
}
|
||||
|
||||
File_Error :: enum u8 {
|
||||
None = 0,
|
||||
Not_A_Directory = 1,
|
||||
Unimplemented = 127,
|
||||
Okay = None,
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
get_working_dir :: proc(allocator := context.allocator) -> (string, Error) {
|
||||
wd, err := os.get_working_directory(allocator)
|
||||
if err != nil {
|
||||
fmt.eprintln("error: get working directory failed:", err)
|
||||
os.exit(1)
|
||||
return {}, err
|
||||
}
|
||||
|
||||
return wd
|
||||
return wd, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user