Repository navigation
fix(core): keep the tokenizer's error context on character boundaries - #791
Merged
Merged
Conversation
tokenize_with_limit builds the "near" text of a syntax error from the five bytes either side of the byte it cannot tokenize. When that window ended inside a multi-byte UTF-8 character, slicing the expression panicked, and the request failed with a panic instead of a ValidationException. Move both ends of the window out to character boundaries, and report the whole character as the token, as tokenize_for already does. Errors for ASCII input are unchanged.
LeeroyHannigan
requested review from
amrith,
c33howard,
jcshepherd and
pdf-amzn
as code owners
November 3, 2026 11:44
LeeroyHannigan
requested review from
eliseong,
hitesh96db,
navareamol and
robinnsc
as code owners
November 3, 2026 11:44
eliseong
approved these changes
Nov 3, 2026
eliseong
left a comment
Collaborator
There was a problem hiding this comment.
This change fixes the request failure and the token it now reports matches the live service. No blocking issues.
These hold on this branch and match the live service:
- An error-context window can fall inside a multi-byte character. On
main, these inputs fail the request. On this branch, they return aValidationException. Two examples: aFilterExpressionof three two-byte characters, and$before a three-byte character. - The reported token is the whole invalid character. The live service does the same.
a = éreturnstoken: "é"anda = 😀returnstoken: "😀", on the service and on this branch. The previous code reported the first byte as a Latin-1 character. - The forward end of the window moves to a character boundary, so a trailing multi-byte character stays whole.
$before a run of three-byte characters returnsnear: "$日日".$xyzwbefore a three-byte character returnsnear: "$xyzw". - This holds for
ConditionExpression,FilterExpression,KeyConditionExpression,UpdateExpression, andProjectionExpression, at the expression size limit, and under deep nesting.
One point is pre-existing and out of scope here. The near window is a fixed five bytes on each side of the token, and the live service builds it from the token stream, one token on each side. attribute_exists(a) $ b returns near: ") $ b" on the service and near: "s(a) $ b" here. #567 already replaces the byte window with a token-based one in both tokenizer entry points and matches the service, so it does not need a separate change.
8 tasks done
3 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
tokenize_with_limitbuilds theneartext of a syntax error from the five bytes either side of the byte it cannot tokenize. When that window ended inside a multi-byte UTF-8 character, slicing the expression string panicked, and the request failed with a panic in its handler instead of aValidationException.tokenize_foralready reports it. Before, a byte that starts a multi-byte character was shown as a single Latin-1 character.tokenize_with_limittokenizesConditionExpressionandFilterExpressionin the engine, and the key condition thedynamodb:LeadingKeyscheck reads.Testing
ValidationException; on main each of them panics at the slice. A multi-byte invalid character is reported whole. An ASCII error keeps its five-byte window.cargo test -p extenddb-core -p extenddb-engine(951 tests),cargo +1.97.0 clippy --all-targets -- -D warnings,cargo fmt --check, andcargo +1.88.0 check --all-targets -p extenddb-core.ADR / RFC: n/a