zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #03952
[Branch ~zeitgeist/zeitgeist/bluebird] Rev 225: Downgrade datamodel assertions to exceptions so Zeitgeist won't
------------------------------------------------------------
revno: 225
committer: Siegfried-Angel Gevatter Pujals <siegfried@xxxxxxxxxxxx>
branch nick: bluebird
timestamp: Mon 2011-09-05 13:16:04 +0200
message:
Downgrade datamodel assertions to exceptions so Zeitgeist won't
crash every time a client sends it something broken.
modified:
src/datamodel.vala
src/errors.vala
--
lp:~zeitgeist/zeitgeist/bluebird
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird
Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala 2011-08-30 13:57:04 +0000
+++ src/datamodel.vala 2011-09-05 11:16:04 +0000
@@ -22,6 +22,13 @@
namespace Zeitgeist
{
+ private void assert_sig (bool condition, string error_message)
+ throws EngineError
+ {
+ if (!condition)
+ throw new EngineError.INVALID_SIGNATURE (error_message);
+ }
+
namespace Timestamp
{
public static int64 now ()
@@ -67,8 +74,10 @@
}
public TimeRange.from_variant (Variant variant)
+ throws EngineError
{
- assert (variant.get_type_string () == "(xx)");
+ assert_sig (variant.get_type_string () == "(xx)",
+ "expected (xx)");
int64 start_msec = 0;
int64 end_msec = 0;
@@ -280,18 +289,18 @@
subjects.add (subject);
}
- public Event.from_variant (Variant event_variant) { // (asaasay)
- assert (event_variant.get_type_string () == "(asaasay)");
+ public Event.from_variant (Variant event_variant) throws EngineError {
+ assert_sig (event_variant.get_type_string () == "(asaasay)",
+ "expected (asaasay)");
VariantIter iter = event_variant.iterator();
- assert (iter.n_children() == 3);
VariantIter event_array = iter.next_value().iterator();
VariantIter subjects_array = iter.next_value().iterator();
Variant payload_variant = iter.next_value ();
var event_props = event_array.n_children ();
- assert (event_props >= 5);
+ assert_sig (event_props >= 5, "expected event_props >= 5");
id = (uint32) uint64.parse (event_array.next_value().get_string ());
var str_timestamp = event_array.next_value().get_string ();
if (str_timestamp == "")
@@ -469,10 +478,12 @@
{
public static GenericArray<Event> from_variant (Variant vevents)
+ throws EngineError
{
GenericArray<Event> events = new GenericArray<Event> ();
- assert (vevents.get_type_string () == "a(asaasay)");
+ assert_sig (vevents.get_type_string () == "a(asaasay)",
+ "expected a(asaasay)");
foreach (Variant event in vevents)
{
@@ -528,11 +539,12 @@
public string current_uri { get; set; }
public Subject.from_variant (Variant subject_variant)
+ throws EngineError
{
VariantIter iter = subject_variant.iterator();
var subject_props = iter.n_children ();
- assert (subject_props >= 7);
+ assert_sig (subject_props >= 7, "expected subject_props >= 7");
uri = iter.next_value().get_string ();
interpretation = iter.next_value().get_string ();
manifestation = iter.next_value().get_string ();
=== modified file 'src/errors.vala'
--- src/errors.vala 2011-09-05 10:27:02 +0000
+++ src/errors.vala 2011-09-05 11:16:04 +0000
@@ -26,6 +26,7 @@
DATABASE_ERROR,
INVALID_ARGUMENT,
INVALID_KEY,
+ INVALID_SIGNATURE, // FIXME: change from EngineError to sth. + public
}
// vala doesn't include proper headers, this fixes it