PHANTOM
🇮🇳 IN
Skip to content

fix(swap): raise error when Jupiter returns empty transaction#196

Merged
onyb merged 1 commit intomasterfrom
jupiter-empty-transaction
Feb 11, 2026
Merged

fix(swap): raise error when Jupiter returns empty transaction#196
onyb merged 1 commit intomasterfrom
jupiter-empty-transaction

Conversation

@onyb
Copy link
Member

@onyb onyb commented Feb 11, 2026

Addresses #163 (comment)

@onyb onyb requested a review from a team February 11, 2026 13:21
@onyb onyb self-assigned this Feb 11, 2026
Copilot AI review requested due to automatic review settings February 11, 2026 13:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds explicit failure handling for an edge case in the Jupiter Ultra V3 order response where the transaction field is present but empty, preventing downstream code from treating an empty transaction as executable.

Changes:

  • Raise an exception when a Jupiter order response contains an empty transaction.
  • Add a unit test covering the empty-transaction case in the Jupiter client.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/api/swap/providers/jupiter/transformations.py Fails fast when the Jupiter order response has no usable transaction payload.
app/api/swap/providers/jupiter/test_client.py Adds coverage asserting the client raises on an empty transaction response.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

...
# raise SwapError
raise ValueError(
"Jupiter order response does not contain a transaction",
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raised ValueError here drops useful context that’s already available in JupiterOrderResponse (e.g., request_id, error_code, error_message). Consider including those fields in the exception message (or raising a SwapError that carries them) so failures caused by empty transactions can be correlated with Jupiter logs/support requests.

Suggested change
"Jupiter order response does not contain a transaction",
"Jupiter order response does not contain a transaction; "
f"request_id={getattr(jupiter_response, 'request_id', None)}, "
f"error_code={getattr(jupiter_response, 'error_code', None)}, "
f"error_message={getattr(jupiter_response, 'error_message', None)}",

Copilot uses AI. Check for mistakes.
Comment on lines +307 to +315
mock_token_manager.get = AsyncMock(return_value=SOL_TOKEN_INFO)

mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
**MOCK_JUPITER_ORDER_RESPONSE,
"transaction": "",
}
mock_httpx_client.get.return_value = mock_response
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test sets mock_token_manager.get to always return SOL_TOKEN_INFO, which can mask token-resolution problems (output/route-plan mints are not SOL) and may exercise a different code path than production. Consider using a side_effect (like other tests in this file) that returns SOL/USDC/(optional intermediate) token infos keyed by mint address, while still keeping the test focused on the empty transaction behavior.

Copilot uses AI. Check for mistakes.
@onyb onyb merged commit 79b96c6 into master Feb 11, 2026
11 checks passed
@onyb onyb deleted the jupiter-empty-transaction branch February 11, 2026 14:36
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.

3 participants