odin-lang/examples

read_console_input example read() error handling seems incorrect

darenc opened this issue · 3 comments

I'm confused here. The example code has this:

n, err := os.read(os.stdin, buf[:])
if err != nil {
    fmt.eprintln("Error reading: ", err)
    return
}

However, that generates the error: Cannot convert untyped value 'nil' to 'Errno' from 'untyped nil'

image

I fixed my test code locally by using the actual success error type returned from os.read().

if err != os.ERROR_NONE {

Maybe testing against 0 is preferable (this is my first day looking at Odin), but nil definitely seems wrong.

I'm confused because this is the result of a fix resulting from #46 and https://github.com/odin-lang/examples/pull/47/files#diff-7acfaa13babebd62dbfca06f65a2209bbf8e1fe25794cc3c3e579becf37510f8, which I presume is working in CI, so I don't understand why I'm getting a problem.

I'm running version dev-2024-08-nightly:8359995

dev-2024-08-nightly:8359995 looks to be the monthly release. Since then core:os has changed how it handles errors. The example has been updated to reflect that change.

@Kelimion Ah, yes that makes sense, thanks.

We're reworking core:os in core:os/os2, and made the former use a union of possible return values similar to the latter. A small breaking change now to avoid a big breaking change later when os2 becomes os. :-)

So that's why. We don't often introduce breaking changes, but it's sometimes unavoidable.