fix(fs)!: handle mkdir error, change error return for cd

breaking change: cd now returns a message instead of a code to indicate the error.
any error in mkdir is now handled
pull/78/head
sammyette 2021-10-16 13:49:01 -04:00
parent 539a39f83a
commit 20acfad2c2
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 8 additions and 13 deletions

View File

@ -40,16 +40,8 @@ func fcd(L *lua.LState) int {
err := os.Chdir(strings.TrimSpace(path)) err := os.Chdir(strings.TrimSpace(path))
if err != nil { if err != nil {
switch e := err.(*os.PathError).Err.Error(); e { e := err.(*os.PathError).Err.Error()
case "no such file or directory": luaErr(L, e)
luaErr(L, 1)
case "not a directory":
luaErr(L, 2)
default:
fmt.Printf("Found unhandled error case: %s\n", e)
fmt.Printf("Report this at https://github.com/Rosettea/Hilbish/issues with the title being: \"fs: unhandled error case %s\", and show what caused it.\n", e)
luaErr(L, 213)
}
} }
return 0 return 0
@ -61,12 +53,15 @@ func fmkdir(L *lua.LState) int {
dirname := L.CheckString(1) dirname := L.CheckString(1)
recursive := L.ToBool(2) recursive := L.ToBool(2)
path := strings.TrimSpace(dirname) path := strings.TrimSpace(dirname)
var err error
// TODO: handle error here
if recursive { if recursive {
os.MkdirAll(path, 0744) err = os.MkdirAll(path, 0744)
} else { } else {
os.Mkdir(path, 0744) err = os.Mkdir(path, 0744)
}
if err != nil {
luaErr(L, err.Error())
} }
return 0 return 0