Skip to content

Commit

Permalink
Remove invalid chars from log prior uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell authored and happz committed Aug 1, 2024
1 parent 86752f5 commit 4452d58
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tmt/steps/report/reportportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def _str_env_to_default(option: str, default: Optional[str]) -> Optional[str]:
return str(os.getenv(env_var))


def _filter_invalid_chars(data: str) -> str:
return re.sub(
'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]+',
'',
data)


@dataclasses.dataclass
class ReportReportPortalData(tmt.steps.report.ReportStepData):

Expand Down Expand Up @@ -231,7 +238,8 @@ def handle_response(self, response: requests.Response) -> None:

if not response.ok:
raise tmt.utils.ReportError(
f"Received non-ok status code {response.status_code} from ReportPortal: {response.text}")
f"Received non-ok status code {response.status_code} "
f"from ReportPortal: {response.text}")

def check_options(self) -> None:
""" Check options for known troublesome combinations """
Expand Down Expand Up @@ -534,7 +542,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
response = session.post(
url=f"{self.get_url()}/log/entry",
headers=self.get_headers(),
json={"message": log,
json={"message": _filter_invalid_chars(log),
"itemUuid": item_uuid,
"launchUuid": launch_uuid,
"level": level,
Expand All @@ -543,7 +551,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:

# Write out failures
if index == 0 and status == "FAILED":
message = result.failures(log)
message = _filter_invalid_chars(result.failures(log))
response = session.post(
url=f"{self.get_url()}/log/entry",
headers=self.get_headers(),
Expand Down

0 comments on commit 4452d58

Please sign in to comment.