From eec930b86a06e74e3cd4292efd1f1e242493baa9 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 18 Sep 2021 10:45:04 +0300 Subject: [PATCH] os: turn some panics into `return error()` --- vlib/os/file.c.v | 4 ++-- vlib/os/os.v | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 40b2ae45f8..b81c72ceb3 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -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 { diff --git a/vlib/os/os.v b/vlib/os/os.v index d0c8aa6d24..8648bf798e 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -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()