Skip to content

Traceback is misleading for http.Client #18650

@melonedo

Description

@melonedo

Zig Version

0.12.0-dev.2250+7116b0221

Steps to Reproduce and Observed Behavior

This script tries to connect to some website, which will fail because I requested a bad URL. However, the traceback is always shown as a failure of certificate parsing as long as the URL begins with https://, regardless of the actual failure.

const std = @import("std");

test "Misleading Traceback" {
    var client = std.http.Client{ .allocator = std.testing.allocator };
    defer client.deinit();

    var header_buf: [100000]u8 = undefined;
    const uri = try std.Uri.parse("https://doesntmatter");
    var req = try std.http.Client.open(&client, .GET, uri, .{
        .server_header_buffer = &header_buf,
    });
    defer req.deinit();
}

The trace back (note the top two entries have nothing to do with the the error here)

mlinux@mlinux ~/C/zig (master) [1]> zig test traceback-issue.zig
Test [1/1] test.Misleading Traceback... FAIL (TemporaryNameServerFailure)
/home/mlinux/Code/install/lib/zig/std/crypto/Certificate.zig:689:40: 0x12dc5a9 in parseEnum__anon_55408 (test)
    return E.map.get(oid_bytes) orelse return error.CertificateHasUnrecognizedObjectId;
                                       ^
/home/mlinux/Code/install/lib/zig/std/crypto/Certificate.zig:680:5: 0x1255eab in parseExtensionId (test)
    return parseEnum(ExtensionId, bytes, element);
    ^
/home/mlinux/Code/install/lib/zig/std/net.zig:58:9: 0x1224074 in parseIp (test)
        return error.InvalidIPAddressFormat;
        ^
/home/mlinux/Code/install/lib/zig/std/net.zig:88:29: 0x1224587 in parseExpectingFamily (test)
            os.AF.UNSPEC => return parseIp(name, port),
                            ^
/home/mlinux/Code/install/lib/zig/std/net.zig:1430:48: 0x122c48a in linuxLookupNameFromDns (test)
    if (ap[0].len < 4 or (ap[0][3] & 15) == 2) return error.TemporaryNameServerFailure;
                                               ^
/home/mlinux/Code/install/lib/zig/std/net.zig:1374:5: 0x122d9a2 in linuxLookupNameFromDnsSearch (test)
    return linuxLookupNameFromDns(addrs, canon, name, family, rc, port);
    ^
/home/mlinux/Code/install/lib/zig/std/net.zig:1013:17: 0x122e7d5 in linuxLookupName (test)
                try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
                ^
/home/mlinux/Code/install/lib/zig/std/net.zig:950:9: 0x11c33ac in getAddressList (test)
        try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
        ^
/home/mlinux/Code/install/lib/zig/std/net.zig:726:18: 0x10f0e5b in tcpConnectToHost (test)
    const list = try getAddressList(allocator, name, port);
                 ^
/home/mlinux/Code/install/lib/zig/std/http/Client.zig:1218:45: 0x10a796d in connectTcp (test)
        error.TemporaryNameServerFailure => return error.TemporaryNameServerFailure,
                                            ^
/home/mlinux/Code/install/lib/zig/std/http/Client.zig:1407:5: 0x10a0d4c in connect (test)
    return client.connectTcp(host, port, protocol);
    ^
/home/mlinux/Code/install/lib/zig/std/http/Client.zig:1489:44: 0x1099f1c in open (test)
    const conn = options.connection orelse try client.connect(host, port, protocol);
                                           ^
/home/mlinux/Code/install/lib/zig/traceback-issue.zig:11:15: 0x109774c in test.Misleading Traceback (test)
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:
/home/mlinux/Code/zig/zig-cache/o/5974229a4f6377269da9545a427ddba9/test

Expected Behavior

The top two entries of trace back should be removed.

Should probably be caused by #18173. Note that #18599 does not fix this.

Edit

Update code for 0.12.0-dev.3161+377ecc6af

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions