Skip to content
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

spend fails without descriptive error #105

Open
Renegatto opened this issue Mar 10, 2023 · 2 comments
Open

spend fails without descriptive error #105

Renegatto opened this issue Mar 10, 2023 · 2 comments
Labels
invalid This doesn't seem right

Comments

@Renegatto
Copy link

Plutus.Model.Contract.spend fails with:

Exception: Maybe.fromJust: Nothing
CallStack (from HasCallStack):
  error, called at libraries/base/Data/Maybe.hs:149:21 in base:Data.Maybe
  fromJust, called at src/Plutus/Model/Contract.hs:276:10 in plutus-simple-model-0.5.2.0-4fEbkvuS1hh58koi6xqmzV:Plutus.Model.Contract

It forces user to dive into PSM source code to figure out the reason of the error, which is not the best user experience.

Proposed solution

Make a descriptive error message.
Maybe even take optional error message as a function parameter.

@Renegatto Renegatto added the invalid This doesn't seem right label Mar 10, 2023
@AgustinBadi
Copy link

Hi @Renegatto !

There's a function called withSpend :: PubKeyHash -> Value -> (UserSpend -> Run ()) -> Run () that serves the same purpose as spend and logs an error if an user doesn't have enough funds. Maybe that can be an awnser to your requirement, or could be that there are other errors that should be catched from your point of view?

Greetings,

@Renegatto
Copy link
Author

Renegatto commented May 16, 2023

Hi, @AgustinBadi.
It's good that such a function exists, but in general in a program (especially in a library) when a function fails it should be clear where and/or why.
I think Exception: Maybe.fromJust: Nothing is not something we expect to see when using library which is not base.

The solution is simply throwing custom (not necessary defined by the library user) error on Nothing instead of using fromJust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants