summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--src/state.c23
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 <d@drobilla.net>
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);