You are working on the hyperswitch repository (Rust payment processing system).…
- User
You are working on the hyperswitch repository (Rust payment processing system).
REPOSITORY SETUP:
- Repository: juspay/hyperswitch
- Working directory: ./repos/hyperswitch_pool_4 (already cloned)
- Base commit: 212ac27057762f9d4cd2073d93c2216f61711cfe
- Task ID: juspay__hyperswitch-7936
- Version: v1.114.0
TASK DESCRIPTION: Bug: [FIX]: Fix error message while using generic filter
Fix error message while using generic filter
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This PR changes the way we raise error if something goes wrong with generic filter. Currently we throw not found error which is wrong.
This feature is hard to test on hosted environments, as this requires to make some db changes so that we can get error in generic filter.
Additional Changes
- This PR modifies the API contract
- This PR modifies the database schema
- This PR modifies application configuration/environment variables
Motivation and Context
We will able able to log correct error messages
How did you test it?
Tested it with dropping
organization_idcolumn in refund table while trying to create refund. According to current implementation, we are raising not found error which is incorrect because it is not displaying the right cause.Implementation in this PR fixes this bug.
Checklist
- I formatted the code
cargo +nightly fmt --all - I addressed lints thrown by
cargo clippy - I reviewed the submitted code
- I added unit tests for my changes where possible
CRITICAL INSTRUCTIONS - WORK FAST AND EFFICIENTLY:
-
Create DENSE, ACTION-FOCUSED todos IMMEDIATELY
- Make todos specific and actionable
- Focus on HIGH-IMPACT actions only
- 5-8 todos maximum - be surgical, not exhaustive
-
Execute aggressively:
- Use bash commands to search efficiently
- Read multiple related files in quick succession
- Make ALL related changes in one edit
- Skip unnecessary exploration
-
File operations:
- All repo files: './repos/hyperswitch_pool_4/'
- Use targeted edits over whole file rewrites
-
NO TESTING UNLESS CRITICAL:
- Focus on making the actual code changes
- Only test if explicitly required
-
Maximize information density:
- Each turn should accomplish significant work
- Batch file reads when examining related code
- Use search commands to locate code quickly
EFFICIENCY IS CRITICAL. Make substantial progress every turn.
Assistant
I'll help you fix the error message issue with the generic filter in the hyperswitch repository. Let me first understand the problem by examining the relevant code.
Let me start by looking at the error message handling and generic filter implementation:
Assistant
Let me search for files related to generic filters and error handling in the codebase to understand the issue better:
Assistant
Let me check the current working directory and explore the repository structure:
Assistant
Now let me search for files related to generic filters and error handling in the crates directory:
Assistant
Let me search in the correct directory structure:
Assistant
Now let me look at the generics.rs file since that's likely where the generic filter implementation is:
Assistant
Now I need to look at the errors module to understand the database error types:
Assistant
Let me check some refund-related files to better understand the context:
Assistant
Now I need to check the schema definition for the refund table to understand the organization_id column:
Assistant
Let me look for the schema directory properly:
Assistant
(no content)
Assistant
Let me examine the schema files:
Assistant
Let me update the todo list and examine the specific issue more closely:
Assistant
Looking at the code I've reviewed, I can now identify the issue. Let me look at line 444 in the generics.rs file more closely, which is where the error occurs:
Assistant
I can see the problem now. On line 444, when a generic filter operation encounters an error, it unconditionally changes the error context to
errors::DatabaseError::NotFound. This is incorrect because it should only change toNotFoundwhen the database actually returns a "not found" error (i.e., when no records match the filter criteria), not for other types of database errors.Let me also check how other functions handle errors to make sure I understand the expected behavior correctly:
Assistant
Perfect! I can see that the
generic_find_one_corefunction correctly handles errors (lines 376-379) by checking specifically forDieselError::NotFoundand only converting toDatabaseError::NotFoundin that case. However, thegeneric_filterfunction unconditionally converts ALL errors toDatabaseError::NotFound.Let me also look at how the other error handling functions work to confirm this pattern:
Assistant
Perfect! This confirms my analysis. In the
generic_update_with_resultsfunction around lines 161-164, we can see the correct pattern:- Line 161: Specifically checks for
DieselError::NotFoundand converts toDatabaseError::NotFound - Line 163-164: For all other errors, it uses
.change_context(errors::DatabaseError::Others)
However, in the
generic_filterfunction at line 444, there's no such check and it unconditionally changes ALL errors toDatabaseError::NotFound.Let me fix this issue:
- Line 161: Specifically checks for
Assistant
I need to read the file first before editing it. Let me check the current state again and then make the edit properly:
Assistant
(no content)
Assistant
I need to read the file first before I can make an edit. Let me do that:
Assistant
Now I can see the problematic code. I'll use the Edit tool to fix the issue by changing the error handling to match the pattern used in other functions in the same file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →