From 2fbfd73d888ef89f80f3093cb45da4a94b7748f7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 15 Jul 2012 17:35:14 +0000 Subject: Gracefully handle failure to save plugin state and print error message. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@4537 a436a847-0d15-0410-975c-d299462d15a1 --- NEWS | 1 + src/state.c | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 7654b51..49d9433 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ lilv (9999) unstable; * Add Lilv::Instance::get_handle() and Lilv::Instance::get_extension_data() * Fix documentation for ui_type parameter of lilv_ui_is_supported() * Fix crash when lv2info is run with an invalid URI argument + * Gracefully handle failure to save plugin state and print error message -- David Robillard diff --git a/src/state.c b/src/state.c index 03485b9..d644528 100644 --- a/src/state.c +++ b/src/state.c @@ -306,6 +306,19 @@ absolute_dir(const char* path) return base; } +static const char* +state_strerror(LV2_State_Status st) +{ + switch (st) { + case LV2_STATE_SUCCESS: return "Completed successfully"; + case LV2_STATE_ERR_UNKNOWN: return "Unknown error"; + case LV2_STATE_ERR_BAD_TYPE: return "Unsupported type"; + case LV2_STATE_ERR_BAD_FLAGS: return "Unsupported flags"; + case LV2_STATE_ERR_NO_FEATURE: return "Missing features"; + case LV2_STATE_ERR_NO_PROPERTY: return "Missing property"; + } +} + LILV_API LilvState* lilv_state_new_from_instance(const LilvPlugin* plugin, @@ -365,8 +378,14 @@ lilv_state_new_from_instance(const LilvPlugin* plugin, : NULL; if (iface) { - iface->save(instance->lv2_handle, store_callback, - state, flags, features); + LV2_State_Status st = iface->save( + instance->lv2_handle, store_callback, state, flags, features); + if (st) { + LILV_ERRORF("Error saving plugin state: %s\n", state_strerror(st)); + free(state->props); + state->props = NULL; + state->num_props = 0; + } } qsort(state->props, state->num_props, sizeof(Property), property_cmp); -- cgit v1.2.1