News for hackers. Stuff that matters.
Re:Show HN: Remult – a CRUD framework for full-stack TypeScript by robocat on Sunday May 22, 2022 @04:08PM (#31472223)
Hmmm, exceptions in validation! Debugger hell.

  export class Product {
    @Fields.string<Product>({
        validate: product => {
            if (product.name.trim().length == 0)
                throw 'required';
        }
    })
    name = '';
Re:Show HN: Remult – a CRUD framework for full-stack TypeScript by hparadiz on Sunday May 22, 2022 @07:30PM (#31473852)
This can work if the controller uses a try catch and handles the exception properly passing the error up the chain to an error output from the rest controller.

Personally I hold the errors in an array which is useful when validating a form when you want to show multiple errors from a save attempt.

However I do throw an exception if the model is somehow incorrectly configured. Like a validator method being expected but not defined.

Re:Show HN: Remult – a CRUD framework for full-stack TypeScript by gabereiser on Sunday May 22, 2022 @06:52PM (#31473595)
I see this a lot with Java style validations. Everything is an exception or can be one. Try catch hell everywhere and there are two schools of thought. Let the exceptions bubble up. Or catch the exceptions you expect at the abstraction, letting the rest bubble up.
Re:Show HN: Remult – a CRUD framework for full-stack TypeScript by robocat on Monday May 23, 2022 @03:13AM (#31476137)
Exceptions are imperative, but validation should be declarative (only requires pure functions to work out validation state given stateful input parameters).

Exceptions are a really bad match for marking validation (even ignoring the arsefest that is debugging exceptions during keyboard input events - ugggh).

The DOM has onInvalid events[1] that are fired on form submit (not blur), and there is an :invalid[2] pseudo class for highlighting input errors. Not a perfect API, but certainly relevantly interesting.

[1] https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputEl...

[2] https://developer.mozilla.org/en-US/docs/Web/CSS/:invalid

Re:Show HN: Remult – a CRUD framework for full-stack TypeScript by smrtinsert on Sunday May 22, 2022 @10:48PM (#31474916)
Well that's weird since java validation frameworks usually collect validation failures before throwing.