Skip to content

Conversation

@lygstate
Copy link
Contributor

Traceback (most recent call last):
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 1019, in <module>
    sys.exit(main())
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 1009, in main
    code = test_suite.run(options.command, args,
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 930, in run
    progress.has_run(result)
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 753, in has_run
    result.report_outcome(True)
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 492, in report_outcome
    self.write_output(sys.stdout)
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 506, in write_output
    target.write("--- errors ---  \n %s" % error)
UnicodeEncodeError: 'gbk' codec can't encode character '\xab' in position 52: illegal multibyte sequence
...............................................=== Summary - updating excludelist ===

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com

```
Traceback (most recent call last):
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 1019, in <module>
    sys.exit(main())
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 1009, in main
    code = test_suite.run(options.command, args,
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 930, in run
    progress.has_run(result)
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 753, in has_run
    result.report_outcome(True)
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 492, in report_outcome
    self.write_output(sys.stdout)
  File "C:\work\study\languages\typescript\jerryscript\tools\runners\test262-harness.py", line 506, in write_output
    target.write("--- errors ---  \n %s" % error)
UnicodeEncodeError: 'gbk' codec can't encode character '\xab' in position 52: illegal multibyte sequence
...............................................=== Summary - updating excludelist ===
```

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
@lygstate lygstate changed the title Fix stdout encoding for python2 and python3 Fix stdout encoding for python2 and python3 in test262-harness.py Jan 18, 2021
out = self.stdout.strip()
if out:
target.write("--- output --- \n %s" % out)
write_text_to(target, u"--- output --- \n%s\n" % out)
Copy link
Member

Choose a reason for hiding this comment

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

If suggestion given at #4390 (review) is applied (i.e., target is opened with a proper encoding), then this change (i.e., wrapping the write into a function) may not even be needed. Please, check and confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If suggestion given at #4390 (review) is applied (i.e., target is opened with a proper encoding), then this change (i.e., wrapping the write into a function) may not even be needed. Please, check and confirm.

Does codecs possible to open stdout/stderr?
Because this target is file or stdout

Copy link
Member

Choose a reason for hiding this comment

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

Stdout or stderr cannot/shouldn't be re-opened, but codecs could still help. Stdout and stderr can be wrapped at the start of the program with something like:

(out_stream, err_stream) = (sys.stdout.buffer, sys.stderr.buffer) if sys.version_info.major >= 3 else (sys.stdout, sys.stderr)

if sys.stdout.encoding != 'UTF-8':
    sys.stdout = codecs.getwriter('utf-8')(out_stream, 'ignore')
if sys.stderr.encoding != 'UTF-8':
    sys.stderr = codecs.getwriter('utf-8')(err_stream, 'ignore')

(disclaimer: untested)

@lygstate lygstate closed this Jan 19, 2021
@lygstate lygstate deleted the fix-stdout-python2-python3 branch January 19, 2021 00:04
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.

2 participants