Repository navigation
Fix issues found during the connection-reuse review - #5
Merged
Merged
Conversation
Only TimeZone tolerated a key sent as null. Every other non-Option field of IpInfo, Asn, Company, Carrier, Language, Currency, Threat, ThreatScores and Blocklist failed the whole response with a decode error, because #[serde(default)] only covers a missing key. Apply the existing null_as_default deserializer to all of them, so a null reads as "", false, 0, 0.0 or an empty list. Field types are unchanged and values of the wrong type are still rejected. Document the rule in the crate docs and the README, and add decoding tests for every model plus a client-level sub-resource test. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
lookup_field carried its own copy of the request, status check and body decoding that get_typed already had, and get and bulk repeated the same status check and decoding a third and fourth time. Make get generic over the decoded type and use it for the full lookups, the raw single-field lookup and the typed sub-resources; move the status check and JSON decoding into decode_response, which bulk uses as well. Behaviour is unchanged: same query parameters, same Error::Api mapping. A test pins lookup_field's error mapping. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
publish.yml ran cargo test and cargo publish on a release without the formatting and lint gates that ci.yml applies to pull requests and pushes to main, so a release could ship code that CI would reject. Add the rustfmt and clippy components to the toolchain step and run cargo fmt --check and cargo clippy --all-targets -- -D warnings before cargo test, mirroring ci.yml. Co-Authored-By: Claude Fable 5.1 <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
Follow-up to #4, fixing the items it listed under "Noticed, not changed" that are defects or gaps: an explicit JSON
nullfailed decoding in every response type exceptTimeZone, the client repeated its request and decoding code four times, and the publish workflow skipped the formatting and lint gates thatci.ymlapplies. Additive only: no public symbol renamed or removed, no field type changed, no version change.Changes
nulldecodes to the field's default in every response type.IpInfo,Asn,Company,Carrier,Language,Currency,Threat,ThreatScoresandBlocklistnow use thenull_as_defaultdeserializer thatTimeZonealready had, on every field that is not anOption. A key sent asnullreads"",false,0,0.0or an empty list instead of failing the whole lookup with a decode error;Optionfields already readNone. Field types are unchanged and values of the wrong type ("latitude": "north","asn": 15169) are still rejected. Documented in the crate docs and the README "Response Types" section. Tests: five new decoding tests intests/types.rs(every model from an all-null document;Threatflags, lists and scores;IpInfoscalars, lists and nested objects; nulls scattered through the anycast fixture with the other values intact; wrong types still rejected) and a wiremock test intests/client.rswhere/carrier,/asnand/time_zoneanswer with nulls.lookup_fieldno longer carries its own copy of the request, status check and decoding.getis generic over the decoded type and serves the full lookups, the raw single-field lookup and the typed sub-resources; the status check and JSON decoding moved todecode_response, whichbulkuses too. No behaviour change: same query parameters, sameError::Apimapping. A new test pinslookup_field's error mapping (a 403 with a JSON message becomesError::Api { status: 403, .. }).publish.ymlruns the same gates asci.yml. The toolchain step installs therustfmtandclippycomponents, andcargo fmt --checkandcargo clippy --all-targets -- -D warningsrun beforecargo testandcargo publish, so a release cannot ship code that CI would reject.Not changed
#[non_exhaustive]on the response structs: it would break every downstream exhaustive struct literal and pattern, a breaking change that does not belong in a patch release.fields=names: the API validates them, and a local list would reject fields added server-side before the crate learns about them.system-proxyfeature stays off: hyper-util's matcher readsHTTP_PROXY,HTTPS_PROXY,ALL_PROXYandNO_PROXYwithout it, and the feature only adds macOS and Windows system settings.Verification
Local, rustc/cargo 1.97.0, run before the push:
cargo fmt --check: clean.cargo clippy --all-targets -- -D warnings: clean (this also compilesexamples/lookup.rs).cargo test:tests/client.rs30 passed (28 before),tests/types.rs13 passed (8 before), doc-tests 3 passed, 0 failed.src/types.rs(invalid type: null, expected a string) and pass with this change; the wrong-type test passes on both.RUSTDOCFLAGS="-D warnings" cargo doc --no-deps: clean, the new intra-doc links resolve.ci.yml) on this pull request: run 41639251359, jobtest:cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testall succeeded on the first attempt (conclusionsuccess).🤖 Generated with Claude Code