karlseguin / pg.zig

Native PostgreSQL driver / client for Zig
MIT License
250 stars 18 forks source link

how to fix it? #36

Closed xiusin closed 3 months ago

xiusin commented 3 months ago
thread 108093 panic: reached unreachable code
/usr/local/Cellar/zig/0.13.0/lib/zig/std/debug.zig:412:14: 0x10151b09c in assert (vendor)
    if (!ok) unreachable; // assertion failure
             ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/lib.zig:39:25: 0x10153b67a in assert (vendor)
        std.debug.assert(ok);
                        ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/types.zig:97:23: 0x1015ef11e in decode (vendor)
            lib.assert(data_oid == Int32.oid.decimal);
                      ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/result.zig:676:41: 0x1015aa8c3 in getScalar__anon_11926 (vendor)
        i32 => return types.Int32.decode(data, oid),
                                        ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/result.zig:272:25: 0x10154dae1 in get__anon_7720 (vendor)
        return getScalar(TT, value.data, self.oids[col]);
                        ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/result.zig:343:42: 0x1015542bd in toUsingOrdinal__anon_7782 (vendor)
            const column_value = self.get(field.type, column_index);
                                         ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/result.zig:334:44: 0x10155461d in to__anon_7781 (vendor)
            .ordinal => self.toUsingOrdinal(T, allocator),
                                           ^
/.cache/zig/p/1220bd73cc6127dad105d12637dbbf0229515c8ec23199c9c8d9caa43cef2d91a8af/src/result.zig:452:27: 0x101554786 in to__anon_7780 (vendor)
        return self.row.to(T, opts);
                          ^
/projects/src/article.zig:40:27: 0x101517aa4 in list (vendor)
    const total = row.?.to(struct { total: i32 = 0 }, .{}) catch |e| return base.send_error(req, e);
                          ^
karlseguin commented 3 months ago

What's the column type? pg.zig is really unforgiving when it comes to type mismatches.

xiusin commented 3 months ago

count(*) AS total, what type should it be?

karlseguin commented 3 months ago

count(*) is a bigint, so it maps to an i64.

I'll spend some time to see if I can improve this aspect of pg.zig...at least try to generate some type of debug error message or something.

xiusin commented 3 months ago

@karlseguin Thank you, it has been resolved through the type you mentioned