Quitting with CTRL+C spawns an error.Unexpected

Hello,
I just ported my chess engine from 0.15.2 to 0.16 and noticed that exitting an infinite loop that reads stdin writes to console error.Unexpected NTSTATUS=0x101 (ALERTED)

This happens on windows, and I use

var stdin_buffer: [16 * 1024]u8 = undefined;
var stdin_reader: std.Io.File.Reader = std.Io.File.stdin().readerStreaming(init.io, &stdin_buffer);
const stdin: *std.Io.Reader = &stdin_reader.interface;

while (true) {
    const line: []u8 = try stdin.takeDelimiter('\n') orelse break;
    _ = line;
}

I put this directly into the main to make sure I wasn’t improperly handling errors.

This does not happen if i remove the takeDelimiter line

Any idea why this happens?

I’m not sure I understand what you’re asking. What did you expect the output would be? A different error?

Waits and APCs - Windows drivers | Microsoft Learn

Simply put, your program is waiting to read new content from stdin, but ctrl-c intterupts the waiting state. The program considers ctrl-c more urgent, so it can only return STATUS_ALERTED.

Hitting an unexpected status is basically always an opportunity to improve the standard library. My suggestion would be:

  • Compile in debug mode to get a stack trace along with the error.Unexpected NTSTATUS info
  • Open an issue with the reproduction steps and the stack trace
  • If you’re up for it (and you have an idea what the fix should be), open a PR with the change

(if the fix is obvious, then you can just skip to making a PR)

1 Like