feat(http): the HTTP layer on ClientHTTP1::Fetch and the typed socket error

Crafter.Network master now carries, in their final shape, the pieces the
HTTP layer and the SQL broker were written against on a side branch:
ClientHTTP1::Fetch follows redirects by RFC 9110 §15.4 on a URL type of
its own, and SocketErrorException is a std::system_error with the phase
that failed. The broker and the HTTP layer read the errno or the resolver
code from code() and the phase from the field, instead of matching
message prefixes, and the pin moves to that commit, so the build no
longer needs --local against a checkout of the side branch.

The messages the run log, the preflight detail and the SQL helper show
are unchanged, but for the wording of a refused URL.
This commit is contained in:
Jorijn van der Graaf 2026-10-31 20:46:13 +01:00
commit 51bdd6298a
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 19 additions and 20 deletions

View file

@ -2,7 +2,6 @@
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
module;
#include <netdb.h>
#include <unistd.h>
#include <cstring>
#include <stdio.h>
@ -141,8 +140,10 @@ namespace Crafter::Review::PgWire {
std::string ConnectErrorText(const std::exception& error) {
if (dynamic_cast<const SocketTimeoutException*>(&error)) return "timed out";
if (const auto* failure = dynamic_cast<const SocketErrorException*>(&error)) {
if (failure->kind == SocketErrorKind::Resolver) return std::format("[Errno {}] {}", failure->code, gai_strerror(failure->code));
return Dyn::ErrnoText(failure->code);
// "[Errno N] text": the resolver's own text for a resolver
// code, the C library's for an errno.
if (failure->code().category() == ResolverCategory()) return std::format("[Errno {}] {}", failure->code().value(), failure->code().message());
return Dyn::ErrnoText(failure->code().value());
}
return error.what();
}
@ -487,7 +488,7 @@ namespace Crafter::Review::PgWire {
} catch (const SocketTimeoutException&) {
throw SocketError("timed out", true);
} catch (const SocketErrorException& error) {
throw SocketError(Dyn::ErrnoText(error.code), false);
throw SocketError(Dyn::ErrnoText(error.code().value()), false);
}
}
const std::size_t take = std::min(count, buffer.size() - position);
@ -510,7 +511,7 @@ namespace Crafter::Review::PgWire {
try {
socket->Send(data.data(), static_cast<std::uint32_t>(data.size()));
} catch (const SocketErrorException& error) {
throw DbError(std::format("the connection broke ({})", Dyn::ErrnoText(error.code)));
throw DbError(std::format("the connection broke ({})", Dyn::ErrnoText(error.code().value())));
} catch (const SocketClosedException&) {
throw DbError(std::format("the connection broke ({})", Dyn::ErrnoText(32)));
}
@ -1170,7 +1171,7 @@ namespace Crafter::Review::PgWire {
out("-- the driver's SQL broker stopped answering mid-call (timed out); nothing of this call was committed");
return ExitSql;
} catch (const SocketErrorException& error) {
out(std::format("-- the driver's SQL broker stopped answering mid-call ({}); nothing of this call was committed", Dyn::ErrnoText(error.code)));
out(std::format("-- the driver's SQL broker stopped answering mid-call ({}); nothing of this call was committed", Dyn::ErrnoText(error.code().value())));
return ExitSql;
} catch (const std::exception& error) {
out(std::format("-- the driver's SQL broker stopped answering mid-call ({}); nothing of this call was committed", error.what()));