Repository navigation
fix(c8y): strip control characters from the operation results - #4412
reubenmiller wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Robot Results
|
Cumulocity rejects an operation status update containing control characters, e.g. the terminal color escape sequences, leaving the operation in the EXECUTING state. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: reubenmiller <[email protected]>
Cumulocity rejects an operation status update containing control characters, which left a c8y_Command operation printing colors in the EXECUTING state. - Remove the control characters, along with the terminal escape sequences they introduce, from the operation results and failure reasons sent to Cumulocity. - Set NO_COLOR=1 and CLICOLOR=0 for the commands run by tedge-shell-plugin, so the tools following either convention don't print colors in the first place. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: reubenmiller <[email protected]>
8a0303c to
14ef115
Compare
|
|
||
| Removes the terminal escape sequences from the failure reason | ||
| ${operation}= Cumulocity.Execute Shell Command | ||
| ... printf '\\033[31merror\\033[0m\\n' >&2; exit 1 |
There was a problem hiding this comment.
[AI] suggestion: Open an issue for a failure reason that loses its error text to an escape-only last line.
tedge-shell-plugin sets the reason to Command returned exit code <N>: <last line>, after trim_end() on the whole output. So printf 'foo\nbar\n\n'; exit 1 gives the reason ...: bar.
In this test, \033[0m comes before the last newline. When \033[0m comes after, as in printf '\033[31merror\n\033[0m' >&2; exit 1, the last line is only \033[0m. fail_operation strips the \033[0m line, and the reason ends with exit code 1: . The PR does not cause the loss: on main, Cumulocity rejected the unstripped ESC, and the operation stayed EXECUTING.
Signed-off-by: reubenmiller <[email protected]>
Signed-off-by: reubenmiller <[email protected]>
Signed-off-by: reubenmiller <[email protected]>
Signed-off-by: reubenmiller <[email protected]>
Proposed changes
A
c8y_Commandoperation whose output contains control characters, e.g. the terminal color escape sequences printed by many CLI tools, stays in the EXECUTING state forever. Cumulocity rejects the506status update with41,506,Message [...] contains invalid charactersonc8y/s/e, which the mapper doesn't act on, while the command has already been cleared on the device. A minimal reproduction is the commandprintf 'a\033b'.This PR:
sanitize_for_smartrestno longer removes control characters, and is renamedtruncate_for_smartrest. The mapper no longer truncates the output of a SmartREST custom operation before the stripping, so the escape sequences don't count toward the size limitNO_COLOR=1andCLICOLOR=0for the commands run bytedge-shell-plugin, so the tools following either convention don't print colors in the first placeThe system tests were pushed first, on their own, and failed on the CI as expected: the operations stayed in the EXECUTING state.
The new system tests cover the
c8y_Commandoperation:printf 'a\033b'NO_COLORandCLICOLORvariables set for the commandThe SmartREST custom operations with a CSV result are covered by a mapper unit test, with an escape character followed by a delimiter.
Types of changes
Paste Link to the issue
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments
a\033bis reported asa, sinceESC bis a valid two-character escape sequence. An unterminated control string, e.g. a window title missing its terminator, is removed up to the end of its line, so a stray escape character cannot remove the following lines.🤖 Generated with Claude Code