Skip to content

Use unsafeCrashWith for unsafeRegex (future fromEither not Partial) + Unix line endings #128

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

Closed
wants to merge 4 commits into from

Conversation

toastal
Copy link
Contributor

@toastal toastal commented Oct 20, 2020

The future version of Data.Either.fromRight is no longer Partial, so fromJust ∘ hush is a way around this as fromJust is still Partial but not ideal. Alternatively, Data.Either should have like Data.Either.Partial.fromRight to restore previous behavior (closes either #56).

It was decided that it would be better to unsafeCrashWith on the Left-hand side of Regex instantiation.

Seemed really out of place to have one file with DOS line endings. Also, purty was run on this.

@toastal toastal changed the title unix line endings Data.Either.fromRight no longer Partial + Unix line endings Oct 20, 2020
@toastal toastal changed the title Data.Either.fromRight no longer Partial + Unix line endings Future Data.Either.fromRight no longer Partial + Unix line endings Oct 20, 2020
@davidchambers
Copy link
Contributor

I suggest splitting this into two pull requests, @toastal, to make the significant changes more apparent in the diff. :)

@toastal toastal marked this pull request as draft October 20, 2020 08:53
@toastal
Copy link
Contributor Author

toastal commented Oct 20, 2020

This PR is as draft while I can figure out what's going out with Data.Either. It makes more sense to do this as one PR whenever that discussion is complete.

@hdgarrood
Copy link
Contributor

I think unsafeRegex itself probably ought to have a Partial constraint, really. Then you can use fromRight (crashWith "...") with the total version of fromRight.

@hdgarrood
Copy link
Contributor

Then again, adding a Partial constraint to unsafeRegex could upset a few people, and might not provide much additional safety if it’s mostly only used at sites where you’d want the constraint to be unsafely discharged anyway (which I suspect is the case).

@natefaubion
Copy link
Contributor

Then you can use fromRight (crashWith "...") with the total version of fromRight

Note, you can't actually use this due to strictness. This will just crash immediately.

@natefaubion
Copy link
Contributor

I think unsafeRegex itself probably ought to have a Partial constraint, really. Then you can use fromRight (crashWith "...") with the total version of fromRight.

Do people use anything but unsafeRegex 😆. I don't think I've ever used anything else, personally. Surely there are no sensible defaults or ways to recover from it, and a crash is a crash.

@hdgarrood
Copy link
Contributor

To be honest, I don't think I've ever used regexes in PureScript in any form.

@hdgarrood
Copy link
Contributor

I think sensible recovery is possible and indeed necessary if you're constructing a regex based on user input or any other data obtained at runtime. Also, just because there's no sensible way of recovering from an invalid regex constructed from a string literal, it doesn't mean a Partial constraint isn't appropriate - in fact I'd say Partial constraints are only for cases where there's no sensible way of recovering. The point of it is just to indicate that the caller needs to be careful, and to give you the option to either discharge it (if the partiality has been dealt with) or propagate it if not.

@natefaubion
Copy link
Contributor

Also, just because there's no sensible way of recovering from an invalid regex constructed from a string literal, it doesn't mean a Partial constraint isn't appropriate - in fact I'd say Partial constraints are only for cases where there's no sensible way of recovering. The point of it is just to indicate that the caller needs to be careful, and to give you the option to either discharge it (if the partiality has been dealt with) or propagate it if not.

FWIW I think we already had this discussion when we added unsafeRegex. I don't see a point in having both an unsafe prefix and a Partial constraint. I don't think this breaking change is worth it IMO.

@hdgarrood
Copy link
Contributor

I agree with not adding a Partial constraint, I just wanted to point out that, imo, not having a sensible way of recovering doesn't justify omitting a Partial constraint in general. For me, the reason not to do it is that it makes the ergonomics terrible, and it doesn't provide very much safety because 99% of the time you would want to discharge the Partial constraint immediately anyway.

@toastal toastal marked this pull request as ready for review October 20, 2020 16:44
@toastal
Copy link
Contributor Author

toastal commented Oct 20, 2020

Not sure how to add a CHANGELOGto this. There's nothing existing already. Is there a dependency issue to be finished here? I've not touched the bower stuff in years.

@hdgarrood
Copy link
Contributor

We don’t store changelog files in the core libraries, we just look over the commit log and add release notes along with each release in GitHub, so no action needed there. There’s also no action needed re dependencies since what you have here will work with both old and new versions of either. When we get around to updating this library properly we will update everything to master temporarily, but that’s not necessary just yet.

@hdgarrood
Copy link
Contributor

Can you show what the errors look like now?

@toastal
Copy link
Contributor Author

toastal commented Oct 21, 2020

@hdgarrood For unsafeRegex "[" noFlags Uncaught Error: unterminated character class. This is the same error as new RegExp("[") in Firefox -- which is less helpful than the Chromium of Uncaught SyntaxError: Invalid regular expression: /[/: Unterminated character class.

Copy link
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

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

Works for me. Thanks!

@toastal toastal changed the title Future Data.Either.fromRight no longer Partial + Unix line endings Use unsafeCrashWith for unsafeRegex (future fromEither, not Partial) + Unix line endings Oct 26, 2020
@toastal toastal changed the title Use unsafeCrashWith for unsafeRegex (future fromEither, not Partial) + Unix line endings Use unsafeCrashWith for unsafeRegex (future fromEither not Partial) + Unix line endings Oct 26, 2020
@JordanMartinez
Copy link
Contributor

This was the same solution I used in #129. Sorry for not including your commits @toastal. I didn't realize this PR already existed.

@toastal
Copy link
Contributor Author

toastal commented Nov 19, 2020

:'( ... I really wanted to be a contributor

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.

Consider Unsafe or Partial for from*
5 participants