Giter Site home page Giter Site logo

Comments (5)

sdiehl avatar sdiehl commented on June 11, 2024

So this is a known breaking change in 0.3.0. since the old interface exposed some partial functions which would fail on encoding errors.

The principled fix would be to go through your codebase and replace all type errors with the function that explicitly handles the UnicodeException with Either.

decodeUtf8' :: ByteString -> Either UnicodeException Text

The less principled fix is to use old interface Protolude.Conv which is left as a compatability layer but it is silently partial. So your business logic may blow up if you pass it malformed strings. Thus the fix in this release.

from protolude.

robx avatar robx commented on June 11, 2024

I understand (I think), but that only really addresses the third point in the list, right? It seems unfortunate that easy ways to encode to UTF8 or to convert between lazy and strict bytestrings were lost.

I'm wondering now whether instances ConvertText _ ByteString would be an option. Though I realize that UTF8-encoded text is not what's understood to be text in the current sense of ConvertText.

from protolude.

sdiehl avatar sdiehl commented on June 11, 2024

I suppose the lazy to strict bytestring conversion exposes potential partiality, but the strict to lazy bytestring should always be safe. I'll look to restoring those to the TextConvert class.

from protolude.

domenkozar avatar domenkozar commented on June 11, 2024

The loss of ConvertText Text ByteString is quite sad, what was partial about that conversion?

from protolude.

adamwespiser avatar adamwespiser commented on June 11, 2024

ConvertText Text ByteString would use encodeUtf8 which is non-partial.

Similarly, the following instances could be added as well:

ConvertText Text ByteString
ConvertText String ByteString
ConvertText Lazy.Text ByteString
ConvertText Text Lazy.ByteString
ConvertText String Lazy.ByteString
ConvertText Lazy.Text Lazy.ByteString

As a convenience, there's definitely merit, but I'm not sure if it would be confusing that you can convert to a ByteString, but not from one using ConvertText. In that way, ConvertText is not sufficient for working with ByteString to Text / String conversions.

I'm not sure what the original intention was here (beyond removing the partial function decodeUtf8 which can cause nasty bugs).
I'm inclined to add the above instances back in. In the meantime, there is toUtf8 and toUtf8Lazy.

from protolude.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.