os: turn some panics into `return error()`

pull/11533/head
Delyan Angelov 2021-09-18 10:45:04 +03:00
parent 209b159554
commit eec930b86a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 3 additions and 2 deletions

View File

@ -370,7 +370,7 @@ pub fn (f &File) read_bytes_at(size int, pos u64) []byte {
// A read call is either stopped, if the buffer is full, a newline was read or EOF.
pub fn (f &File) read_bytes_into_newline(mut buf []byte) ?int {
if buf.len == 0 {
panic(@FN + ': `buf.len` == 0')
return error(@FN + ': `buf.len` == 0')
}
newline := 10
mut c := 0
@ -409,7 +409,7 @@ pub fn (f &File) read_bytes_into_newline(mut buf []byte) ?int {
// Returns the number of read bytes, or an error.
pub fn (f &File) read_bytes_into(pos u64, mut buf []byte) ?int {
if buf.len == 0 {
panic(@FN + ': `buf.len` == 0')
return error(@FN + ': `buf.len` == 0')
}
$if x64 {
$if windows {

View File

@ -82,6 +82,7 @@ pub fn mv_by_cp(source string, target string) ? {
}
// read_lines reads the file in `path` into an array of lines.
[manualfree]
pub fn read_lines(path string) ?[]string {
buf := read_file(path) ?
res := buf.split_into_lines()