Skip to content

xcresult_logs.py: Fix potential UnicodeEncodeError #9645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2022

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Apr 13, 2022

This PR fixes the following UnicodeDecodeError that sometimes happens in GitHub actions:

Traceback (most recent call last):
  File "scripts/xcresult_logs.py", line 300, in <module>
    main()
  File "scripts/xcresult_logs.py", line 67, in main
    sys.stdout.write(log)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 421: ordinal not in range(128)

e.g. https://github.com/firebase/firebase-ios-sdk/runs/6000587971

#no-changelog

@dconeybe dconeybe self-assigned this Apr 13, 2022
@dconeybe dconeybe requested a review from paulb777 April 13, 2022 14:28
dconeybe added a commit that referenced this pull request Apr 13, 2022
… on iOS to verify the fix to xcresult_logs.py in #9645
Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

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

Thanks!

@dconeybe
Copy link
Contributor Author

Hmm, this fix didn't work. Instead, I got

Traceback (most recent call last):
  File "scripts/xcresult_logs.py", line 312, in <module>
    main()
  File "scripts/xcresult_logs.py", line 73, in main
    log_encoded = log.encode(sys.stdout.encoding, errors='backslashreplace')
TypeError: encode() argument 1 must be string, not None

https://github.com/firebase/firebase-ios-sdk/runs/6009395104

I'm going to try a different approach.

… instead just encode to UTF-8 in a relaxed manner and write the resulting bytes directly to stdout
@dconeybe
Copy link
Contributor Author

That fix didn't work either. It looks like sys.stdout doesn't have a buffer attribute. This time I got this exception:

Traceback (most recent call last):
  File "scripts/xcresult_logs.py", line 305, in <module>
    main()
  File "scripts/xcresult_logs.py", line 72, in main
    sys.stdout.buffer.write(log_encoded)
AttributeError: 'file' object has no attribute 'buffer'

e.g. https://github.com/firebase/firebase-ios-sdk/runs/6011521209

I've pushed 1b5d296 to try a different approach again.

@dconeybe
Copy link
Contributor Author

Finally, that worked. I'm going to merge this now.

e.g. https://github.com/firebase/firebase-ios-sdk/runs/6012727534

@dconeybe dconeybe merged commit 8af6c20 into master Apr 13, 2022
@dconeybe dconeybe deleted the dconeybe/XcResultUnicodeEncodeErrorFix branch April 13, 2022 20:02
dconeybe added a commit that referenced this pull request Apr 13, 2022
… to fail on iOS to verify the fix to xcresult_logs.py in #9645"

This reverts commit 73a558c.
@firebase firebase locked and limited conversation to collaborators May 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants