-
Notifications
You must be signed in to change notification settings - Fork 132
Remove fatalError from implementation of ByteString description #155
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
Remove fatalError from implementation of ByteString description #155
Conversation
Remove fatalError from implementation of ByteString description
|
@swift-ci please test |
MaxDesiatov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I, for one, welcome this change. That fatalError there always made me feel uncomfortable.
|
Thanks for fixing this! I agree, this seems like a good change. I don't know the history here either, but a I had noticed the I think we also have a new test failure in |
|
One of the changes here will be that if the byte string contains invalid UTF-8, they will be replaced with invalid-character markers. Since The API here seems due for a cleanup at some point. Like many things in ToolsSupportCore, it dates back to when the Swift standard library wasn't so mature yet, and I know that one big problem in Swift 1 was the performance of String, and especially quickly going to and from UTF-8. That's all different now, with String being backed by UTF-8, so I would imagine that a lot of the APIs that use ByteStrings could really use regular strings today. |
|
|
@abertelrud Please let me know if there's anything left to do for this to get merged. I'm currently hitting this in my work on package registry (specifically |
|
This looks good to me. |
The current implementation of the
descriptionproperty required forByteStringto conform toCustomStringConvertibleincludes a call tofatalErrorif the buffer constitutes an invalid UTF-8 byte sequence:https://github.com/apple/swift-tools-support-core/blob/e618e0f0f82fbfcff1a5a097ba0d019c7d6ddcc5/Sources/TSCBasic/ByteString.swift#L110-L116
According to the header documentation:
Based on that, it's surprising to me that the type would enforce that the byte string is UTF-8 valid, or that calling
description(most often implicitly) could cause a program to trap. I encountered this behavior when generating and verifyingSHA256checksums.In the process of
throw-ing thatmismatchedChecksumserror in a unit test,XCTestattempted to call the synthesizeddescriptionproperty, which delegated toByteString's implementation. My workaround was to change the associated value types toStringand use each checksum'shexadecimalRepresentation.Unfortunately, the context of this change appears to have been lost when TSCBasic et al. were consolidated into this monorepo (fcaa2ce), so I can only guess at the original motivation here. This PR replaces the existing implementation with a call to
cString. Tests pass all the same (though FWIW,PkgConfigParserTests.testBrewPrefixis failing locally before and after the commit...), though I don't have particularly strong feelings withcStringas the thing to use here. If anyone has a any different ideas, I'd be interested to hear them.