Skip to content

Fixing the lexical error Hello-world test#2509

Open
ramdrvcs wants to merge 1 commit into
skupperproject:mainfrom
ramdrvcs:main
Open

Fixing the lexical error Hello-world test#2509
ramdrvcs wants to merge 1 commit into
skupperproject:mainfrom
ramdrvcs:main

Conversation

@ramdrvcs

@ramdrvcs ramdrvcs commented Jun 24, 2026

Copy link
Copy Markdown

While I was running the E2E tests, I had the follwing error for hello-world module.

fatal: [west]: FAILED! => {"attempts": 30, "changed": true, "msg": "Task failed: Action failed: Unknown error.", "rc": 1, "return_code": 1, 
"stderr": "cannot parse the data: `lexical error: invalid character inside string.\n
{\"user\":{\"uid\":0,\"gid\":0,\"addi\n                     (right here) ------^\n`\n",
"stderr_lines": ["cannot parse the data: `lexical error: invalid character inside string.", " 
{\"user\":{\"uid\":0,\"gid\":0,\"addi", "                     (right here) ------^", "`"], 
"stdout": "", "stdout_lines": []}

Description

Fixes a critical runtime failure in the run_curl role where the task fails with an Unknown 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...}}). When kubernetes.core.k8s_exec catches 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)

  • Pipe the curl response through base64 and tr -d "\n" inside the container before printing to stdout.
  • This neutralizes special characters ({, ", :) into a flat alphanumeric string, completely bypassing the execution engine's JSON parsing bug.

2. Optimize Network Efficiency & Prevent Race Conditions

  • Refactored the script to use a temporary file (mktemp) to store the curl output.
  • This reduces network traffic by 50% (making exactly one HTTP call to {{ run_curl_address }} per loop cycle instead of two separate calls).
  • Eliminates a potential race condition where the HTTP status code and response payload could mismatch if the server state changed between back-to-back requests.
  • Ensures strict disk hygiene by cleaning up with rm -f "$tmp_file" immediately after processing.

3. Shell Script Robustness

  • Enclosed the entire sh -c payload in literal single quotes ('...') to stop Ansible from misinterpreting $response, $code, and $tmp_file as local playbook variables.
  • Double-quoted "$code" inside the shell evaluation block to prevent a unary operator expected syntax crash if a curl request returns empty.

Testing Triaged

  • Verified that payloads containing nested JSON quotes no longer trigger a lexical error.
  • Confirmed that the loop correctly runs exactly one HTTP request per retry iteration.
  • Confirmed the task successfully completed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved end-to-end curl output handling by returning a base64-encoded response body (for both success and failure), reducing issues with parsing and formatting.
    • Updated the debug/output behavior to extract the encoded payload, decode it, and display only the decoded response body rather than the full command output.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The run_curl Ansible role now base64-encodes the HTTP response body before returning it, and the debug step decodes that value before printing it.

Changes

run_curl role response encoding

Layer / File(s) Summary
curl exec encoding and debug decode
tests/e2e/collections/ansible_collections/e2e/tests/roles/run_curl/tasks/main.yml
Shell command changed to base64-encode the response body and prefix it with BODY_BASE64; debug task changed to extract BODY_BASE64 via regex_search and decode it with b64decode before printing.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is clearly related to the main change: fixing the hello-world test's lexical parsing error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands.

@ramdrvcs ramdrvcs marked this pull request as ready for review June 24, 2026 09:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f4f2b3 and 466bb5c.

📒 Files selected for processing (1)
  • tests/e2e/collections/ansible_collections/e2e/tests/roles/run_curl/tasks/main.yml

Comment thread tests/e2e/collections/ansible_collections/e2e/tests/roles/run_curl/tasks/main.yml Outdated
@ramdrvcs ramdrvcs marked this pull request as draft June 24, 2026 12:39
@ramdrvcs ramdrvcs marked this pull request as ready for review June 24, 2026 12:39
@hash-d hash-d requested review from granzoto and hash-d June 24, 2026 12:52
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.

1 participant