Re: [Vala] Contract programming and error messages



Hi,

On Tue, 2012-07-10 at 16:20 +0200, marcin saepia net wrote:
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.

I think we should use the Vala source string, i.e., `valid_thread()' in
your example, instead of extending syntax to allow custom error
messages. Assertion messages have been improved the same way in Vala
0.17.1. This could be implemented using the helper function
`g_return_if_fail_warning'.

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.

Yes, it would be nice to improve this, and this should be possible
without requiring any changes in the application code. However, to not
break GLib API conventions, we should never return a GError due to a
contract failure, i.e., this should be changed for D-Bus call only. As
methods exported to D-Bus may also be called from within the process, a
proper implementation may be a bit more work than expected.

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

I'd say it's bad practice to throw errors from such functions. It may be
possible to remove this limitation at some point, but I'd prefer the two
improvements described above.

Regards,
Jürg




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