Skip to content

Conversation

@scottrepreneur
Copy link
Contributor

Summary

Fixes BUILD-1144 where Ethereum addresses (42 characters) caused 400 Bad Request errors when searching users via the Neynar API, which has a requirement that the q parameter must be 20 characters or less.

Changes

  • Input Validation: Added pre-API validation in searchUsersByUsername() to check string length
  • Ethereum Address Detection: Special handling for 42-char strings starting with 0x
  • Error Handling: Updated /search route to return proper 400 responses with descriptive messages
  • Test Coverage: Added comprehensive tests for validation edge cases

Root Cause

The Neynar /v2/farcaster/user/search endpoint validates that the q parameter is ≤20 characters. When users attempted to search with Ethereum addresses like 0x0B5f5a722Ac5E8EcEDf4da39A656fe5f1e76b34C, the API returned:

{"code":"InvalidField","message":"q must be a string of length 20 or less","property":"q"}

Solution

  • Input validation before making API calls prevents 400 errors
  • Clear user feedback about search limitations
  • Maintains backward compatibility for valid searches

Test Plan

  • Added unit tests for Ethereum address search validation
  • Added unit tests for long query validation
  • Added unit tests for 20-character limit boundary
  • Verified existing search functionality still works
  • All new tests passing

🤖 Generated with Claude Code

Addresses BUILD-1144 where Ethereum addresses (42 chars) caused 400 Bad Request
errors when searching users via Neynar API, which requires q param ≤20 chars.

Changes:
- Add input validation in searchUsersByUsername() before API call
- Handle Ethereum addresses (0x + 42 chars) with specific error message
- Handle any query >20 chars with generic length error message
- Update /search route to return 400 with descriptive errors
- Add comprehensive tests for validation edge cases

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@linear
Copy link

linear bot commented Aug 29, 2025

BUILD-1144 Neynar has a lookup by name requirement of 20 characters

# Appears to be an issue with the address input here. Not sure who is attempting with address



<-- POST /api/v1/users/search
[DEBUG] 🔍 DEBUG: Starting user search for username: "0x0B5f5a722Ac5E8EcEDf4da39A656fe5f1e76b34C"
[DEBUG] 🔍 DEBUG: Cleaned username: "0x0B5f5a722Ac5E8EcEDf4da39A656fe5f1e76b34C"
[DEBUG] 🔍 DEBUG: Neynar API key configured, making search request for: "0x0B5f5a722Ac5E8EcEDf4da39A656fe5f1e76b34C"
[DEBUG] 🔍 DEBUG: API URL: https://api.neynar.com/v2/farcaster/user/search?q=0x0B5f5a722Ac5E8EcEDf4da39A656fe5f1e76b34C
[DEBUG] 🔍 DEBUG: Neynar API response status: 400 Bad Request
[ERROR] ❌ DEBUG: Neynar API error: 400 Bad Request {"code":"InvalidField","message":"q must be a string of length 20 or less","property":"q"}
[ERROR] ❌ DEBUG: Error during user search: 88658 |             users: []
88659 |           };
88660 |         }
88661 |         const errorText = await response.text();
88662 |         logger3.error(`\u274C DEBUG: Neynar API error: ${response.status} ${response.statusText}`, errorText);
88663 |         throw new Error(`Neynar API error: ${response.status} ${response.statusText}`);
                               ^
error: Neynar API error: 400 Bad Request
      at searchUsersByUsername (/app/dist/index.js:88663:24)
 
--> POST /api/v1/users/search 500 19ms

@scottrepreneur scottrepreneur merged commit b3d3c4a into main Aug 29, 2025
1 check passed
@scottrepreneur scottrepreneur deleted the feature/build-1144-neynar-20-char-limit branch August 29, 2025 18:10
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.

2 participants