Silencing unexpected errors from std.posix syscalls in debug builds

I’m working with nonblocking datagram file sockets on an embedded yocto Linux platform. In this configuration, calling sendto on a socket file that doesn’t exist can sometimes set errno to 2 (file not found), and sometimes 111 (connection refused).

error.ConnectionRefused, is not in the error set for std.posix.sendto, so when sendto triggers that error, I get an unexpected error and a stack trace printout from Zig.

I can handle the error just fine.

Is there anything I can do to silence the printing from my debug builds, besides patching the standard library?

It is in the error set:

error.Unexpected is always indicative of a bug in the standard library; system error codes that trigger error.Unexpected should be handled once they are known to be possible.

(note also that the debug printing only happens in Debug mode)

2 Likes

I am confused about your reproduction, though. std.posix.sendto handles ENOENT and ECONNREFUSED. Could you provide exactly the error.Unexpected debug printing you’re hitting / the full reproduction?

EDIT: Actually, it looks like ECONNREFUSED was added as a possible error two days after 0.13.0 released: Add ECONNREFUSED to sendto by onlined · Pull Request #20223 · ziglang/zig · GitHub

4 Likes

Can confirm, present on 13.0 and fixed on 14.0.
I’ve upgraded my toolchain to the current release.

Do people generally follow the master branch?

Edit: Noted that error.Unexpected should always be considered a bug.
Good to know in case I hit on something like it in the future.

3 Likes