[Vala] Contract programming and error messages



Hi,

I use vala contract programming features to ensure that several
functions are called from proper thread. I've created helper function
for that to DRY, and the effect is that in case of failure I got error
message like this:

my_function: assertion `_tmp0_' failed

out of

requires(valid_thread())

Error message is not self-explanatory at all, but I understand that it
behaves like that due to C representation of the reqires() code.

It would be nice to have possibility to attach somehow desired error
message to requires() that will be shown instead of current one.

The another problem is that if that function is exported over D-Bus
and requires() constraints are not fulfilled, no error is thrown over
D-Bus, function just returns nothing.

I've tried to throw error from valid_thread, but it is prohibited, I
got "error: Field initializers must not throw errors".


Nice solution that solves the issue would be just to change the last
behavior, and allow to throw errors within requires() block. Error
message could be displayed instead of "assertion `_tmp0_' failed" and
forwarded to D-Bus.

What do you think about that?

I can spend some time on preparing the patch but only if such feature
would be accepted by vala core team.

m.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]