Fixing the lexical error Hello-world test#2509
Open
ramdrvcs wants to merge 1 commit into
Open
Conversation
📝 WalkthroughWalkthroughThe Changesrun_curl role response encoding
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4fabd917-9871-463f-91d8-71e5570d176b
📒 Files selected for processing (1)
tests/e2e/collections/ansible_collections/e2e/tests/roles/run_curl/tasks/main.yml
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.
While I was running the E2E tests, I had the follwing error for hello-world module.
Description
Fixes a critical runtime failure in the
run_curlrole where the task fails with anUnknown error(lexical error: invalid character inside string).The failure occurs because the target endpoint returns a raw JSON payload containing nested double quotes (e.g.,
{"user":{"uid":0...}}). Whenkubernetes.core.k8s_execcatches the stdout stream, these raw quotes break the internal parser of the Ansible execution engine.This PR addresses the parsing error via Base64 encoding and optimizes the network footprint of the task by caching the payload to a temporary file.
Changes
1. Fix Shell Parsing Error (Lexical Exception)
curlresponse throughbase64andtr -d "\n"inside the container before printing to stdout.{,",:) into a flat alphanumeric string, completely bypassing the execution engine's JSON parsing bug.2. Optimize Network Efficiency & Prevent Race Conditions
mktemp) to store the curl output.{{ run_curl_address }}per loop cycle instead of two separate calls).rm -f "$tmp_file"immediately after processing.3. Shell Script Robustness
sh -cpayload in literal single quotes ('...') to stop Ansible from misinterpreting$response,$code, and$tmp_fileas local playbook variables."$code"inside the shell evaluation block to prevent aunary operator expectedsyntax crash if a curl request returns empty.Testing Triaged
lexical error.Summary by CodeRabbit