Skip to content

Conversation

@yanxue-22
Copy link
Contributor

@yanxue-22 yanxue-22 commented Oct 29, 2025

Ticket: DX-2214

This PR attempts to validate this following fix, which resolved an issue introduced by this Regression Commit.

Original Problem

The system encountered an error when parsing certain Arrow Functions with parameters (e.g., (codec) => t.array(codec)), specifically: Error: Error when parsing AdminUpdateShardKeyApiSpec: Unknown identifier codec.

Cause: The parser attempts to inline the function body for optimization. During this process, it failed because the parameters (like codec) were not recognized in the symbol table, leading to the "Unknown identifier" error.
Previous Behavior: The old code immediately returned the parsing error upon inlining failure, preventing it from checking for custom codec definitions as a necessary fallback.


Why the Fix Works (Utilizing E.isRight Check)

The fix modifies the parser's logic to handle inlining failures gracefully, allowing it to proceed to the custom codec check:

  1. Instead of immediately returning the result of parseFunctionBody(...), the code now stores the result in a variable (bodyResult).
  2. It then uses an E.isRight(bodyResult) check.
    • If successful (right): The successful result is returned.
    • If it fails (left/error): The code does not return immediately. It continues execution, allowing it to reach the subsequent logic that checks for custom codec definitions.

This ensures that even if the inlining optimization fails, the parser still attempts to find a valid definition using custom codecs. Predefined codecs are found in const knownImport = project.resolveKnownImport(imp.from, imp.importedName); inside the codecIdentifier function.


Testing the Fix

The test validates that the type parser correctly falls back to using a pre-defined custom codec for a field utilizing an arrow function with parameters (arrayFromArrayOrSingle(NonEmptyString)), ensuring it resolves to an array type without throwing an Unknown identifier codec error.

@yanxue-22 yanxue-22 changed the title test: add comprehensive tests for arrow function fallback behavior test: add tests for arrow function fallback behavior Oct 29, 2025
@yanxue-22 yanxue-22 force-pushed the DX-2214-Test-Fix-For-Unknown-identifer-codec branch 5 times, most recently from f8824ed to bf9c320 Compare November 4, 2025 00:50
Check if parseFunctionBody() succeeded before returning, allowing parser
to use custom codec definitions when function contains parameter references.
@yanxue-22 yanxue-22 force-pushed the DX-2214-Test-Fix-For-Unknown-identifer-codec branch from bf9c320 to 465569a Compare November 4, 2025 01:07
@yanxue-22 yanxue-22 marked this pull request as ready for review November 4, 2025 01:14
@yanxue-22 yanxue-22 requested a review from a team as a code owner November 4, 2025 01:14
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