Add netcode_client_create_error so callers can tell why create failed#148
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
netcode_client_createreturning NULL was undifferentiated. Each failure path now records an error code, queryable when create returns NULL:NETCODE_CLIENT_CREATE_ERROR_NONE(0) — last create succeededNETCODE_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_errorcovers 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
🤖 Generated with Claude Code