Full Code: nrv30/int-base-converter: convert u64 between hex, octal, binary, decimal. My first zig project!
I made a REPL program, so I print error messages to the user.
if (stdout_writer) |writer| {
try writer.writeAll("Invalid Command. Missing '('\n");
try writer.flush();
}
return error.InvalidCommand;
I have to check stdout_writer is not null every time because I made it optional. The reason I did this is because I want to be able to pass the writer as null in my test code to avoid printing the error messages. I wanted to ask if there’s a better strategy because it feels a bit hacky.
It’s also being repeated many times, so I wanted to make it a helper function. However, I can’t figure out if there’s a way to signal that a function always returns an error. If I do pub fn name() !void it’s inaccurate because the function never returns nothing, it always returns an error.
I asked AI, it recommended me to use @TypeOf(error.InvalidCommand). Do you guys agree with this advice? I found it kina confusing, but it looked like what I was trying to do.
Thanks!