#Error while formatting an error type

1 messages · Page 1 of 1 (latest)

tardy pendant
#

The following code:

    decode24(out.slice(), str) catch |err| {
        debug("error: {}", .{err});
        unreachable;
    };

Generates the following compile error:

/usr/lib/zig/std/mem.zig:205:17: error: unable to evaluate comptime expression
        dest[i] = s;
        ~~~~~~~~^~~
/usr/lib/zig/std/mem.zig:205:13: note: operation is runtime due to this operand
        dest[i] = s;
        ~~~~^~~
/usr/lib/zig/std/io/fixed_buffer_stream.zig:70:21: note: called from here
            mem.copy(u8, self.buffer[self.pos .. self.pos + n], bytes[0..n]);
            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/std/io/writer.zig:17:27: note: called from here
            return writeFn(self.context, bytes);
                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/std/io/writer.zig:23:40: note: called from here
                index += try self.write(bytes[index..]);
                             ~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/lib/zig/std/fmt.zig:121:32: note: called from here
            try writer.writeAll(fmt[start_index..end_index]);
                ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/std/fmt.zig:1954:15: note: called from here
    try format(fbs.writer(), fmt, args);
        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/home/kuon/pbg/zkfs-sdk/js/src/common/log.zig:16:31: note: called from here
    var buf = std.fmt.bufPrint(&log_buf, format ++ "\r\n", args) catch {
              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/std/log.zig:125:22: note: called from here
    std.options.logFn(message_level, scope, format, args);
    ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/std/log.zig:203:16: note: called from here
            log(.debug, scope, format, args);
            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/client.zig:17:14: note: called from here
        debug("error: {}", .{err});
        ~~~~~^~~~~~~~~~~~~~~~~~~~~
src/client.zig:24:24: note: called from here

Am I doing something wrong or is it a zig bug?

formal beacon
#

Sounds like you're trying to do this at a comptime scope

#

Also unreachable is most likely not what you want here. It's UB in non-safe modes.

tardy pendant
#

yes it's just to test

#

we cannot print error at comptime for debugging?

formal beacon
#

No, you cannot use syscalls during comptime

tardy pendant
#

I should use @compileError to inspect an error at compile time?

formal beacon
#

You can use @compileLog as that doesn't stop compilation at the first occurance it hits. It does however fail compilation at the end.

tardy pendant
#

ok thanks

#

the error message could be improved 😄

formal beacon
#

Sure

tardy pendant
#

do you think it is worth making an issue if there is not already one?

formal beacon
#

Can’t decide that for you. To me the error message is clear as day, but that’s probably because of experience. There’s an issue template exactly for error messages, so it’s probably worth it if there isn’t one.

tardy pendant
#

yeah now that I realize what cause it, it is clear, but having a small hint "you cannot make syscall at comptime, use @compileLog" would have saved me some time.

#

I'll make an issue

#

thanks a lot for your help