Programmatic invalidation in remote form will prevent error being thrown
Describe the bug
given - using the new remote form function with enhance()
when - programmatically invalidating something from within the remote form function with invalid()
then - subsequent calls to error() will exit the function but the error will not be thrown on the client
expected - a call to invalid() should not change the behavior of error()
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-e7rfdu7j?file=src%2Froutes%2Fform.remote.ts
Logs
System Info
System:
OS: Windows 11 10.0.26100
CPU: (8) x64 Intel(R) Xeon(R) W-2125 CPU @ 4.00GHz
Memory: 11.57 GB / 31.68 GB
Binaries:
Node: 24.9.0 - C:\Program Files\nodejs\node.EXE
npm: 11.6.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (140.0.3485.54)
Firefox: 140.0.4 - C:\Program Files\Mozilla Firefox\firefox.exe
Internet Explorer: 11.0.26100.1882
npmPackages:
@sveltejs/adapter-node: ^5.2.12 => 5.3.3
@sveltejs/enhanced-img: ^0.6.0 => 0.6.1
@sveltejs/kit: ^2.20.2 => 2.46.4
@sveltejs/vite-plugin-svelte: ^5.0.3 => 5.1.1
svelte: ^5.33.13 => 5.39.11
vite: ^6.2.3 => 6.3.6
Severity
annoyance
Additional Information
Ideally, calling error() should not just throw consistently. It would be good if even in the error case the issues raised by the remote function are populated and available to the client. This would allow to pass general error information while also returning proper error codes for further telemetry (not a fan of HTTP 200 with success: false...).
But I'm not sure what exactly the intended design behavior is.
This is the intended behavior. invalid throws a ValidationError and error throws an HttpError. As they both throw, they both block the rest of the script from executing. You wouldn't want to raise an error and let invalid db calls be made because the script continued executing.
Though I can see an argument that it should be a 400 error, as the user has sent something incorrect.
Ah well could help if one would properly read the full documentation. The first sentence was a bit misleading for me and thus I missed the part stating that invalid actually throws. Thanks for clarifying.
Yeah in this case I still hope it would be a 400 and ending up in the catch on the client. Having to do an additional manual check (where one would have to count the numer of allIssues()?) before resetting the form in the success path is a bit weird.
Just stumbled upon another behaviour that is (presumably) caused by returning HTTP 200 for validation issues: when used as a login form and submitting an invalid password (or just empty to trigger schema validation), a password manager interprets the login as success and offers to save the password even though login actually failed