Skip to content

Add netcode_client_create_error so callers can tell why create failed#148

Merged
gafferongames merged 1 commit into
mainfrom
client-create-error
Jul 9, 2026
Merged

Add netcode_client_create_error so callers can tell why create failed#148
gafferongames merged 1 commit into
mainfrom
client-create-error

Conversation

@gafferongames

Copy link
Copy Markdown
Contributor

Summary

netcode_client_create returning NULL was undifferentiated. Each failure path now records an error code, queryable when create returns NULL:

  • NETCODE_CLIENT_CREATE_ERROR_NONE (0) — last create succeeded
  • NETCODE_CLIENT_CREATE_ERROR_PARSE_ADDRESS_FAILED (1) / PARSE_ADDRESS2_FAILED (2)
  • NETCODE_CLIENT_CREATE_ERROR_SIMULATOR_REQUIRES_PORT (3)
  • NETCODE_CLIENT_CREATE_ERROR_CREATE_SOCKET_IPV4_FAILED (4) / CREATE_SOCKET_IPV6_FAILED (5)
  • NETCODE_CLIENT_CREATE_ERROR_ALLOCATE_CLIENT_FAILED (6)

Accessor: int netcode_client_create_error(). The socket-create helper picks the IPv4/IPv6 code from the address family it was given; a successful create resets the error to NONE. Global storage, consistent with the library's documented single-threaded design.

test_client_create_error covers every code — including real port-in-use bind collisions for both address families and a failing allocator for the allocation path. Suite is now 41 tests.

Test plan

  • Local macOS: Release, Debug, ASan+UBSan pass 41/41
  • CI green on all 9 jobs

🤖 Generated with Claude Code

netcode_client_create returning NULL was undifferentiated: a bad address
string, a socket creation failure, the network simulator port requirement,
and allocation failure all looked the same to the caller.

Each failure path in client create now records a
NETCODE_CLIENT_CREATE_ERROR_* code, queryable via
netcode_client_create_error() when create returns NULL. A successful
create resets it to NETCODE_CLIENT_CREATE_ERROR_NONE.

Adds test_client_create_error covering every code, including port-in-use
socket failures for both address families and a failing allocator.
Suite is now 41 tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gafferongames gafferongames merged commit de310e5 into main Jul 9, 2026
8 checks passed
@gafferongames gafferongames deleted the client-create-error branch July 9, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant