diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-11-14 14:59:03 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-14 14:59:03 +0000 |
| commit | 360d93bfa1c4dd1fce19705cf532cf54feb173d3 (patch) | |
| tree | 84b90a922b4b89e00560631abffd56aacd075fb2 | |
| parent | bd21b2cf49cc27515df911bc57397f8833035c73 (diff) | |
| parent | e4fcebe4bf715cf60ccb74f2a03abca995ca608f (diff) | |
Merge pull request #5928 from odin-lang/bill/io-error-changes
Move some OS General_Error values to io.Error
| -rw-r--r-- | core/bufio/read_writer.odin | 2 | ||||
| -rw-r--r-- | core/bufio/reader.odin | 2 | ||||
| -rw-r--r-- | core/bufio/writer.odin | 2 | ||||
| -rw-r--r-- | core/bytes/buffer.odin | 2 | ||||
| -rw-r--r-- | core/bytes/reader.odin | 2 | ||||
| -rw-r--r-- | core/c/libc/stdio.odin | 2 | ||||
| -rw-r--r-- | core/compress/common.odin | 8 | ||||
| -rw-r--r-- | core/fmt/fmt_js.odin | 2 | ||||
| -rw-r--r-- | core/io/io.odin | 40 | ||||
| -rw-r--r-- | core/io/multi.odin | 4 | ||||
| -rw-r--r-- | core/io/util.odin | 4 | ||||
| -rw-r--r-- | core/os/errors.odin | 18 | ||||
| -rw-r--r-- | core/os/os2/errors.odin | 18 | ||||
| -rw-r--r-- | core/os/os2/file_linux.odin | 4 | ||||
| -rw-r--r-- | core/os/os2/file_posix.odin | 2 | ||||
| -rw-r--r-- | core/os/os2/file_wasi.odin | 2 | ||||
| -rw-r--r-- | core/os/os2/file_windows.odin | 2 | ||||
| -rw-r--r-- | core/os/stream.odin | 2 | ||||
| -rw-r--r-- | core/strings/builder.odin | 2 | ||||
| -rw-r--r-- | core/strings/reader.odin | 2 |
20 files changed, 60 insertions, 62 deletions
diff --git a/core/bufio/read_writer.odin b/core/bufio/read_writer.odin index 3e6bd3aa0..84769b9a6 100644 --- a/core/bufio/read_writer.odin +++ b/core/bufio/read_writer.odin @@ -38,5 +38,5 @@ _read_writer_procedure := proc(stream_data: rawptr, mode: io.Stream_Mode, p: []b case .Query: return io.query_utility({.Flush, .Read, .Write, .Query}) } - return 0, .Empty + return 0, .Unsupported }
\ No newline at end of file diff --git a/core/bufio/reader.odin b/core/bufio/reader.odin index 4aa1e6c5d..7ab7da5b7 100644 --- a/core/bufio/reader.odin +++ b/core/bufio/reader.odin @@ -347,7 +347,7 @@ _reader_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse case .Query: return io.query_utility({.Read, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } // diff --git a/core/bufio/writer.odin b/core/bufio/writer.odin index 9c73baf87..618264933 100644 --- a/core/bufio/writer.odin +++ b/core/bufio/writer.odin @@ -249,5 +249,5 @@ _writer_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse case .Query: return io.query_utility({.Flush, .Write, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index f4d883353..dd4b378c0 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -434,5 +434,5 @@ _buffer_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse case .Query: return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } diff --git a/core/bytes/reader.odin b/core/bytes/reader.odin index 2e1c5ed42..184f93835 100644 --- a/core/bytes/reader.odin +++ b/core/bytes/reader.odin @@ -160,6 +160,6 @@ _reader_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse case .Query: return io.query_utility({.Read, .Read_At, .Seek, .Size, .Query}) } - return 0, .Empty + return 0, .Unsupported } diff --git a/core/c/libc/stdio.odin b/core/c/libc/stdio.odin index aa92e4a6b..db5b202e7 100644 --- a/core/c/libc/stdio.odin +++ b/core/c/libc/stdio.odin @@ -390,7 +390,7 @@ to_stream :: proc(file: ^FILE) -> io.Stream { } case .Destroy: - return 0, .Empty + return 0, .Unsupported case .Query: return io.query_utility({ .Close, .Flush, .Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Query }) diff --git a/core/compress/common.odin b/core/compress/common.odin index 39aa1ca72..d78aec328 100644 --- a/core/compress/common.odin +++ b/core/compress/common.odin @@ -297,7 +297,7 @@ peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid curr := z.input->impl_seek(0, .Current) or_return r, e1 := io.to_reader_at(z.input) if !e1 { - return T{}, .Empty + return T{}, .Unsupported } when size <= 128 { b: [size]u8 @@ -306,7 +306,7 @@ peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid } _, e2 := io.read_at(r, b[:], curr) if e2 != .None { - return T{}, .Empty + return T{}, .Unsupported } res = (^T)(&b[0])^ @@ -324,7 +324,7 @@ peek_data_at_offset_from_stream :: #force_inline proc(z: ^Context_Stream_Input, r, e3 := io.to_reader_at(z.input) if !e3 { - return T{}, .Empty + return T{}, .Unsupported } when size <= 128 { b: [size]u8 @@ -333,7 +333,7 @@ peek_data_at_offset_from_stream :: #force_inline proc(z: ^Context_Stream_Input, } _, e4 := io.read_at(r, b[:], pos) if e4 != .None { - return T{}, .Empty + return T{}, .Unsupported } // Return read head to original position. diff --git a/core/fmt/fmt_js.odin b/core/fmt/fmt_js.odin index ce90fbfe7..4ec6bd9a8 100644 --- a/core/fmt/fmt_js.odin +++ b/core/fmt/fmt_js.odin @@ -19,7 +19,7 @@ write_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, write(fd, p) return i64(len(p)), nil } - return 0, .Empty + return 0, .Unsupported } @(private="file") diff --git a/core/io/io.odin b/core/io/io.odin index 2c9b4379f..9fae30946 100644 --- a/core/io/io.odin +++ b/core/io/io.odin @@ -38,8 +38,11 @@ Error :: enum i32 { // This is usually a sign of a broken `io.Reader` implementation No_Progress, + // Invalid whence argument Invalid_Whence, + // Invalid offset Invalid_Offset, + // Invalid "unread" operation Invalid_Unread, Negative_Read, @@ -50,8 +53,19 @@ Error :: enum i32 { // Unknown means that an error has occurred but cannot be categorized Unknown, - // Empty is returned when a procedure has not been implemented for an io.Stream - Empty = -1, + // Indicates that an attempt to retrieve a Stream's size was made, but the + // stream doesn't have a size. + No_Size, + + Permission_Denied, + + // Stream cannot be used since it has been Closed + Closed, + + // Unsupported is returned when a procedure has not been implemented for an io.Stream + Unsupported = -1, + + Empty = Unsupported, } Stream_Mode :: enum { @@ -102,7 +116,7 @@ destroy :: proc(s: Stream) -> (err: Error) { if s.procedure != nil { _, err = s.procedure(s.data, .Destroy, nil, 0, nil) } else { - err = .Empty + err = .Unsupported } return } @@ -138,7 +152,7 @@ read :: proc(s: Reader, p: []byte, n_read: ^int = nil) -> (n: int, err: Error) { n = int(n64) if n_read != nil { n_read^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -151,7 +165,7 @@ write :: proc(s: Writer, p: []byte, n_written: ^int = nil) -> (n: int, err: Erro n = int(n64) if n_written != nil { n_written^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -167,7 +181,7 @@ seek :: proc(s: Seeker, offset: i64, whence: Seek_From) -> (n: i64, err: Error) if s.procedure != nil { n, err = s.procedure(s.data, .Seek, nil, offset, whence) } else { - err = .Empty + err = .Unsupported } return } @@ -192,7 +206,7 @@ flush :: proc(s: Flusher) -> (err: Error) { size :: proc(s: Stream) -> (n: i64, err: Error) { if s.procedure != nil { n, err = s.procedure(s.data, .Size, nil, 0, nil) - if err == .Empty { + if err == .Unsupported { n = 0 curr := seek(s, 0, .Current) or_return end := seek(s, 0, .End) or_return @@ -200,7 +214,7 @@ size :: proc(s: Stream) -> (n: i64, err: Error) { n = end } } else { - err = .Empty + err = .Unsupported } return } @@ -217,7 +231,7 @@ read_at :: proc(r: Reader_At, p: []byte, offset: i64, n_read: ^int = nil) -> (n: if r.procedure != nil { n64: i64 n64, err = r.procedure(r.data, .Read_At, p, offset, nil) - if err != .Empty { + if err != .Unsupported { n = int(n64) } else { curr := seek(r, offset, .Current) or_return @@ -229,7 +243,7 @@ read_at :: proc(r: Reader_At, p: []byte, offset: i64, n_read: ^int = nil) -> (n: } if n_read != nil { n_read^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -243,7 +257,7 @@ write_at :: proc(w: Writer_At, p: []byte, offset: i64, n_written: ^int = nil) -> if w.procedure != nil { n64: i64 n64, err = w.procedure(w.data, .Write_At, p, offset, nil) - if err != .Empty { + if err != .Unsupported { n = int(n64) } else { curr := seek(w, offset, .Current) or_return @@ -255,7 +269,7 @@ write_at :: proc(w: Writer_At, p: []byte, offset: i64, n_written: ^int = nil) -> } if n_written != nil { n_written^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -440,7 +454,7 @@ copy_n :: proc(dst: Writer, src: Reader, n: i64) -> (written: i64, err: Error) { @(private) _copy_buffer :: proc(dst: Writer, src: Reader, buf: []byte) -> (written: i64, err: Error) { if dst.procedure == nil || src.procedure == nil { - return 0, .Empty + return 0, .Unsupported } buf := buf if buf == nil { diff --git a/core/io/multi.odin b/core/io/multi.odin index e25e8133e..abd9b9c5e 100644 --- a/core/io/multi.odin +++ b/core/io/multi.odin @@ -8,7 +8,7 @@ _multi_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, of if mode == .Query { return query_utility({.Read, .Query}) } else if mode != .Read { - return 0, .Empty + return 0, .Unsupported } mr := (^Multi_Reader)(stream_data) for len(mr.readers) > 0 { @@ -61,7 +61,7 @@ _multi_writer_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, of if mode == .Query { return query_utility({.Write, .Query}) } else if mode != .Write { - return 0, .Empty + return 0, .Unsupported } mw := (^Multi_Writer)(stream_data) for w in mw.writers { diff --git a/core/io/util.odin b/core/io/util.odin index a956a5975..86a89cfb1 100644 --- a/core/io/util.odin +++ b/core/io/util.odin @@ -354,7 +354,7 @@ _tee_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, offs case .Query: return query_utility({.Read, .Query}) } - return 0, .Empty + return 0, .Unsupported } // tee_reader_init returns a Reader that writes to 'w' what it reads from 'r' @@ -404,7 +404,7 @@ _limited_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, case .Query: return query_utility({.Read, .Query}) } - return 0, .Empty + return 0, .Unsupported } limited_reader_init :: proc(l: ^Limited_Reader, r: Reader, n: i64) -> Reader { diff --git a/core/os/errors.odin b/core/os/errors.odin index bf4cf27ff..fcf70ec74 100644 --- a/core/os/errors.odin +++ b/core/os/errors.odin @@ -11,19 +11,13 @@ Platform_Error :: _Platform_Error General_Error :: enum u32 { None, - Permission_Denied, Exist, Not_Exist, - Closed, Timeout, Broken_Pipe, - // Indicates that an attempt to retrieve a file's size was made, but the - // file doesn't have a size. - No_Size, - Invalid_File, Invalid_Dir, Invalid_Path, @@ -31,8 +25,6 @@ General_Error :: enum u32 { Pattern_Has_Separator, - Unsupported, - File_Is_Pipe, Not_Dir, @@ -70,18 +62,14 @@ error_string :: proc "contextless" (ferr: Error) -> string { case General_Error: switch e { case .None: return "" - case .Permission_Denied: return "permission denied" case .Exist: return "file already exists" case .Not_Exist: return "file does not exist" - case .Closed: return "file already closed" case .Timeout: return "i/o timeout" case .Broken_Pipe: return "Broken pipe" - case .No_Size: return "file has no definite size" case .Invalid_File: return "invalid file" case .Invalid_Dir: return "invalid directory" case .Invalid_Path: return "invalid path" case .Invalid_Callback: return "invalid callback" - case .Unsupported: return "unsupported" case .Pattern_Has_Separator: return "pattern has separator" case .File_Is_Pipe: return "file is pipe" case .Not_Dir: return "file is not directory" @@ -103,7 +91,11 @@ error_string :: proc "contextless" (ferr: Error) -> string { case .Negative_Write: return "negative write" case .Negative_Count: return "negative count" case .Buffer_Full: return "buffer full" - case .Unknown, .Empty: // + case .Permission_Denied: return "permission denied" + case .Closed: return "file already closed" + case .No_Size: return "file has no definite size" + case .Unsupported: return "unsupported" + case .Unknown: // } case runtime.Allocator_Error: switch e { diff --git a/core/os/os2/errors.odin b/core/os/os2/errors.odin index 077697c0d..2d959e182 100644 --- a/core/os/os2/errors.odin +++ b/core/os/os2/errors.odin @@ -10,19 +10,13 @@ import "base:runtime" General_Error :: enum u32 { None, - Permission_Denied, Exist, Not_Exist, - Closed, Timeout, Broken_Pipe, - // Indicates that an attempt to retrieve a file's size was made, but the - // file doesn't have a size. - No_Size, - Invalid_File, Invalid_Dir, Invalid_Path, @@ -33,8 +27,6 @@ General_Error :: enum u32 { No_HOME_Variable, Env_Var_Not_Found, - - Unsupported, } // A platform specific error @@ -72,19 +64,15 @@ error_string :: proc(ferr: Error) -> string { case General_Error: switch e { case .None: return "" - case .Permission_Denied: return "permission denied" case .Exist: return "file already exists" case .Not_Exist: return "file does not exist" - case .Closed: return "file already closed" case .Timeout: return "i/o timeout" case .Broken_Pipe: return "Broken pipe" - case .No_Size: return "file has no definite size" case .Invalid_File: return "invalid file" case .Invalid_Dir: return "invalid directory" case .Invalid_Path: return "invalid path" case .Invalid_Callback: return "invalid callback" case .Invalid_Command: return "invalid command" - case .Unsupported: return "unsupported" case .Pattern_Has_Separator: return "pattern has separator" case .No_HOME_Variable: return "no $HOME variable" case .Env_Var_Not_Found: return "environment variable not found" @@ -105,7 +93,11 @@ error_string :: proc(ferr: Error) -> string { case .Negative_Write: return "negative write" case .Negative_Count: return "negative count" case .Buffer_Full: return "buffer full" - case .Unknown, .Empty: // + case .Permission_Denied: return "permission denied" + case .Closed: return "file already closed" + case .No_Size: return "file has no definite size" + case .Unsupported: return "unsupported" + case .Unknown: // } case runtime.Allocator_Error: switch e { diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin index b2350d9b5..6d66ffd75 100644 --- a/core/os/os2/file_linux.odin +++ b/core/os/os2/file_linux.odin @@ -515,7 +515,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, case .Query: return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } @@ -559,6 +559,6 @@ _file_stream_buffered_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: case .Query: return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } diff --git a/core/os/os2/file_posix.odin b/core/os/os2/file_posix.odin index fd409b9d4..f445cb5f4 100644 --- a/core/os/os2/file_posix.odin +++ b/core/os/os2/file_posix.odin @@ -502,6 +502,6 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query}) case: - return 0, .Empty + return 0, .Unsupported } } diff --git a/core/os/os2/file_wasi.odin b/core/os/os2/file_wasi.odin index ec464fc52..b60cce4be 100644 --- a/core/os/os2/file_wasi.odin +++ b/core/os/os2/file_wasi.odin @@ -557,6 +557,6 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query}) case: - return 0, .Empty + return 0, .Unsupported } } diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin index be5aeb8ab..03fbc596e 100644 --- a/core/os/os2/file_windows.odin +++ b/core/os/os2/file_windows.odin @@ -866,7 +866,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, case .Query: return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } diff --git a/core/os/stream.odin b/core/os/stream.odin index 39edc9cd5..f4e9bcdde 100644 --- a/core/os/stream.odin +++ b/core/os/stream.odin @@ -62,7 +62,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, case .Size: n, os_err = file_size(fd) case .Destroy: - err = .Empty + err = .Unsupported case .Query: return io.query_utility({.Close, .Flush, .Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Query}) } diff --git a/core/strings/builder.odin b/core/strings/builder.odin index 285ced9ce..a6d0b24b3 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -182,7 +182,7 @@ _builder_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byt case .Query: return io.query_utility({.Write, .Size, .Destroy, .Query}) } - return 0, .Empty + return 0, .Unsupported } /* diff --git a/core/strings/reader.odin b/core/strings/reader.odin index bb49bf917..0d467f285 100644 --- a/core/strings/reader.odin +++ b/core/strings/reader.odin @@ -310,5 +310,5 @@ _reader_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse case .Query: return io.query_utility({.Size, .Read, .Read_At, .Seek, .Query}) } - return 0, .Empty + return 0, .Unsupported } |