Skip to content

Prevent no_std websocket request-id panic when id is missing#314

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-get-random-id-no-std-panic
Draft

Prevent no_std websocket request-id panic when id is missing#314
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-get-random-id-no-std-panic

Conversation

Copilot AI commented May 24, 2026

Copy link
Copy Markdown

High Level Overview of Change

no_std websocket requests could panic when id was omitted: set_request_id hit unimplemented!() and request_impl unwrapped id. This change converts that path to explicit error handling and removes the panic source.

  • XRPLClient::set_request_id no_std behavior

    • Removed the unimplemented!() branch for not(feature = "std").
    • In no_std, missing id is now left unchanged instead of panicking.
  • No_std websocket request path

    • Replaced unwrap() on request.get_common_fields().id with a checked path returning XRPLWebSocketException::InvalidMessage.
  • Regression coverage

    • Added a no_std unit test verifying set_request_id does not panic and does not synthesize an ID.

Context of Change

The bug was in the no_std websocket request flow: request IDs are auto-generated only in std, but no_std code still assumed an ID exists and panicked at runtime if callers did not pre-set one. This update makes no_std behavior deterministic and non-panicking by surfacing a normal client error.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Before / After

Before (no_std):

self.set_request_id(&mut request);
let request_id = request.get_common_fields().id.as_ref().unwrap();

After (no_std):

self.set_request_id(&mut request);
let request_id = request
    .get_common_fields()
    .id
    .as_ref()
    .ok_or(XRPLWebSocketException::InvalidMessage)?;

Test Plan

Added unit coverage for no_std request ID handling in src/asynch/clients/client.rs:

  • set_request_id_no_std_does_not_panic_or_generate_id

Copilot AI changed the title [WIP] Fix panic in get_random_id for no_std builds Prevent no_std websocket request-id panic when id is missing May 24, 2026
Copilot AI requested a review from e-desouza May 24, 2026 01:50
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.

get_random_id() no_std panics with unimplemented!()

2 participants