Error/Validation handling

Hello dear Wappler superstars,

I’m trying to take advantage of the Library feature to have reusable actions.
The problem I’m facing is with validation handling.

Unless I missed something…
Whenever there is a validation error, it stops the original server action that is calling the library.
I can’t intercept validation errors to implement my own logic with try catch blocks for instance.

Use case is : Webhook receives contact informations to process.
It might contain or not a phone number.
If it does, we have to clean it through a library server action and format it to e164 standard.
Now in the lib…
Depending on the phone number format, the lib can require an additional country field to be provided.
If it’s missing, it would throw an error.
Back in the webhook action…
We would intercept that error, skip the phone number logic and continue to process the other contact info fields.

I haven’t followed all recent improvement but always felt like error handling was a weakspot in 3.X
It’s like some components are made to make your life easier but… you can’t really use them… and have to go back to custom coding your logic if you want tight error/validation handling on all fronts (api included).

Any improvements already available or planned in the future on that matter ?

Thank you very much for your help !

Hi. From what I understand, you are configuring this wrong.
If an input can be optional, it should not have any input validations in the first place. You need to put the logic in the library steps to handle if a certain field is available or not.

In the lib, the validator is only used when the country field is indeed required (there is a case where it’s not required).
If it’s required, that’s not the only thing we do with the validator : we check it’s a 2 characters long string, uppercase and letters only.

I find it convenient with the validator as it’s visual and error free.
If I have to custom code this with “if logic”, it becomes error prone…

Unless there is another solution to control how to validate and then cascade errors/validations the way we want in the parent server action ?

I am not getting your point entirely.
You want to put in condition/check/try-catch in the parent server action, but if you do the same in library SA it becomes error prone?

All error/validations work in a universal way. Be it in include-library SA or exec-library SA or regular SA.
So I don’t think there needs to be a change in the way Wappler functions here.

Also, the validator step does not “throw” an error, which can be caught. It returns an error response if validation fails. And response function is also universal in a way that wherever you put a response, it will stop the execution of SA and return from there.

Maybe I get it all wrong but the way I’ve learned to code…
You would create functions (the equivalent of server action libraries) to create your most basic routines that will be called over and over from the other part of your program.
Then on the top of those libraries, you can either build more libraries with a higher level of abstraction and additional business logic.
In Wappler, at the highest level, you have your server action API .

What I feel is lacking is the control of how errors/validations are cascading in Wappler.

Let’s say I have API server action > Lib A server action > Lib B server action.
Maybe I want to validate certain parameters at the API level, or the Lib A or the Lib B level depending on my business logic.

The way it is implemented right now doesn’t give any flexibility :

  • Either we have to custom code all validations and our own error handling logic… losing the “point and click - fast, easy & error free” advantage.
  • Or we use the blocks but can only have validation errors stopping the execution and bubbling up at the highest level right away… Without having the choice of handling those validation errors further with an alternative workflow.

In my use case, if I want to save contact informations.
I have for instance a lib to validate and clean phone numbers.
A lib to validate and clean postal addresses.
Etc…
When a contact has an invalid phone number (or any other provided field).
I don’t want wappler to stop it’s execution just because one field is not valid. I want to be able to handle that case in the business logic. Where I save everything else and just discard what can’t be validated for instance.

Can I custom code it ? Sure.
Is it really low-code and error free then ? No.

Makes sense ? :slight_smile:

I get your point from a theoretical view. But its not practical. You need to adapt your implementation based on the tool you are using. In this case Wappler.

You don’t have to custom code anything in the flow that you want, as I understand.
Its just more steps in the SAs. Various conditions & try catch steps for handling all the possible pitfalls that you want to handle, the way you want to handle.

There is nothing to “custom code”. Everything is just steps.
Its is still low-code & error free. Just more steps than usual.

This is what you get with Wappler - visual way to build complex business logic like you want. Don’t find components that fit in…? You can custom code server side modules to get work done.