os: replace panics with optionals (#5718)

pull/5719/head
yuyi 2020-07-07 18:41:42 +08:00 committed by GitHub
parent a6450e8e98
commit 4490cd2e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -238,12 +238,12 @@ pub fn cp_all(osource_path, odest_path string, overwrite bool) ? {
dp := os.join_path(dest_path, file)
if os.is_dir(sp) {
os.mkdir(dp) or {
panic(err)
return error(err)
}
}
cp_all(sp, dp, overwrite) or {
os.rmdir(dp)
panic(err)
return error(err)
}
}
}
@ -1223,7 +1223,7 @@ pub fn flush() {
C.fflush(C.stdout)
}
pub fn mkdir_all(path string) {
pub fn mkdir_all(path string) ? {
mut p := if path.starts_with(os.path_separator) { os.path_separator } else { '' }
path_parts := path.trim_left(os.path_separator).split(os.path_separator)
for subdir in path_parts {
@ -1232,7 +1232,7 @@ pub fn mkdir_all(path string) {
continue
}
os.mkdir(p) or {
panic('folder: $p, error: $err')
return error('folder: $p, error: $err')
}
}
}