emmanueltouzery / prelude-ts

Functional programming, immutable collections and FP constructs for typescript and javascript
ISC License
377 stars 21 forks source link

Make preludeTsContractViolationCb throw an exception instead of a string? #59

Closed malcolmredheron closed 1 year ago

malcolmredheron commented 2 years ago

Is it intentional that preludeTsContractViolationCb (https://github.com/emmanueltouzery/prelude-ts/blob/736e40c9dcea6a3179daf1db52152159e0ab7236/src/Contract.ts#L4) throws a string instead of an exception?

In my setup (with Mocha), when a test throws a string I don't get a stack trace. When it throws an exception, I do. Thus, running setContractViolationAction((message) => { throw new Error(message); }); before tests makes for much nicer errors.

But if you don't have objections, I think that it would be great to just change preludeTsContractViolationCb to do this by default.

emmanueltouzery commented 2 years ago

Yes, you're right, it would be better, thankfully it can be changed by the user. If you make a PR I'll merge it and release, otherwise I'll do it at some point when I make the next release.

malcolmredheron commented 2 years ago

Great! I have a fork of your repo that includes separate branches for several changes that I made, including this one. But I see now that I accidentally included in each of my branches a change that enables me to use a github branch in my fork directly from npm (without building it and pushing it to npmjs.com). I've sent you a PR for that. If you want it, then I'll keep my other branches as they are and can send you a PR for this and a few others. If you don't want it then I'll clean up my branches first.

emmanueltouzery commented 1 year ago

fixed by the PR