settings: log warnings if setting does not exist in the schema

This commit is contained in:
Julian Bouzas
2024-03-04 07:51:37 -05:00
parent ee366446b6
commit 00e5c0d7f8

View File

@@ -812,8 +812,10 @@ wp_settings_get (WpSettings *self, const gchar *name)
g_return_val_if_fail (name, NULL); g_return_val_if_fail (name, NULL);
spec = wp_settings_get_spec (self, name); spec = wp_settings_get_spec (self, name);
if (!spec) if (!spec) {
wp_warning ("Setting '%s' does not exist in the settings schema", name);
return NULL; return NULL;
}
m = g_weak_ref_get (&self->metadata); m = g_weak_ref_get (&self->metadata);
if (!m) if (!m)
@@ -836,11 +838,18 @@ WpSpaJson *
wp_settings_get_saved (WpSettings *self, const gchar *name) wp_settings_get_saved (WpSettings *self, const gchar *name)
{ {
const gchar *value; const gchar *value;
g_autoptr (WpSettingsSpec) spec = NULL;
g_autoptr (WpMetadata) mp = NULL; g_autoptr (WpMetadata) mp = NULL;
g_return_val_if_fail (WP_IS_SETTINGS (self), NULL); g_return_val_if_fail (WP_IS_SETTINGS (self), NULL);
g_return_val_if_fail (name, NULL); g_return_val_if_fail (name, NULL);
spec = wp_settings_get_spec (self, name);
if (!spec) {
wp_warning ("Setting '%s' does not exist in the settings schema", name);
return NULL;
}
mp = g_weak_ref_get (&self->metadata_persistent); mp = g_weak_ref_get (&self->metadata_persistent);
if (!mp) if (!mp)
return NULL; return NULL;
@@ -892,13 +901,17 @@ wp_settings_set (WpSettings *self, const gchar *name, WpSpaJson *value)
return FALSE; return FALSE;
spec = wp_settings_get_spec (self, name); spec = wp_settings_get_spec (self, name);
if (!spec) if (!spec) {
return FALSE; wp_warning ("Setting '%s' does not exist in the settings schema", name);
if (!wp_settings_spec_check_value (spec, value))
return FALSE; return FALSE;
}
value_str = wp_spa_json_to_string (value); value_str = wp_spa_json_to_string (value);
if (!wp_settings_spec_check_value (spec, value)) {
wp_warning ("Cannot set setting '%s' with value: %s", name, value_str);
return FALSE;
}
wp_metadata_set (m, 0, name, "Spa:String:JSON", value_str); wp_metadata_set (m, 0, name, "Spa:String:JSON", value_str);
return TRUE; return TRUE;
} }
@@ -920,8 +933,10 @@ wp_settings_reset (WpSettings *self, const char *name)
g_return_val_if_fail (name, FALSE); g_return_val_if_fail (name, FALSE);
spec = wp_settings_get_spec (self, name); spec = wp_settings_get_spec (self, name);
if (!spec) if (!spec) {
wp_warning ("Setting '%s' does not exist in the settings schema", name);
return FALSE; return FALSE;
}
def_value = wp_settings_spec_get_default_value (spec); def_value = wp_settings_spec_get_default_value (spec);
return wp_settings_set (self, name, def_value); return wp_settings_set (self, name, def_value);
@@ -968,10 +983,17 @@ gboolean
wp_settings_delete (WpSettings *self, const char *name) wp_settings_delete (WpSettings *self, const char *name)
{ {
g_autoptr (WpMetadata) mp = NULL; g_autoptr (WpMetadata) mp = NULL;
g_autoptr (WpSettingsSpec) spec = NULL;
g_return_val_if_fail (WP_IS_SETTINGS (self), FALSE); g_return_val_if_fail (WP_IS_SETTINGS (self), FALSE);
g_return_val_if_fail (name, FALSE); g_return_val_if_fail (name, FALSE);
spec = wp_settings_get_spec (self, name);
if (!spec) {
wp_warning ("Setting '%s' does not exist in the settings schema", name);
return FALSE;
}
mp = g_weak_ref_get (&self->metadata_persistent); mp = g_weak_ref_get (&self->metadata_persistent);
if (!mp) if (!mp)
return FALSE; return FALSE;