Open meaku opened 12 years ago
I'm not sure about timeouts anymore. It's hard to set a fixed limit for validators. We could do it like mocha and provide setters for the timeout in the validator-function. But i think it's not the best idea.
The problem is had was caused by a validator which returned undefined but was a sync-validator. So alamid was waiting for the callback, as it is expecting functions to be async if undefined is returned. (that's why this issue exists)
We could prevent this by counting the passed arguments, as validators have a fixed amount of arguments.
validate : function(fieldName, callback)
I think that's the right solution for now.
What do you think @jhnns ?
If it's fixed, we may rely on the length-attribute. But it would be cool if alamid would be consistent in all these cases. So that alamid always checks for the length-attribute.
We should use arg-length checking whenever possible. The "undefined" way of sync-async handling will only be applied if the length of arguments is not fixed.
Why did the validator return undefined? Using the return value seems to me a bit less error-prone.
There was a bug in my code causing the validator to return undefined instead of a boolean. In this case nothing happens anymore, because alamid is waiting for the callback. Stupid to debug.
I think using argument length in less error prone-prone. If you want the validator async you will have a callback argument anyway. If you return undefined in this case, alamid would treat it as "undefined" error code and return.
Ok. So do we still need a timeout?
No timeout. Just different handling of the response in order to check if sync or async. I'll also have to add a test for slightly delayed async responses. I had a bug which passed the tests.
What's the current state of it?
It's a pain in the ass if you are waiting for a validator-function which never returns. I'll add a timeout which can be disabled or set the way mocha handles it.
If a validator times out, it will return "timeout" as an error message for the field and the whole validation will fail.