Fix/config save error handling (#150)

* fix(docs): Add trailing newlines to documentation files

* fix(web): Resolve font configuration loading error on first page load

- Remove ineffective DOMContentLoaded listener from fonts partial (loads via HTMX after main page DOMContentLoaded)
- Add proper HTMX event handling with htmx:afterSettle for reliable initialization
- Add duplicate initialization protection flag
- Improve error handling with response validation and clearer error messages
- Add fallback initialization check for edge cases
- Ensure DOM elements exist before attempting initialization

Fixes issue where 'Error loading font configuration' appeared on first web UI load when opening fonts tab.

* fix(config): Update plugins_directory to plugin-repos in config template

The web-ui-info plugin is located in plugin-repos/ directory, but the
config template was pointing to plugins/ directory. This caused the
plugin to not be discovered on fresh installations.

- Changed plugins_directory from 'plugins' to 'plugin-repos' in config.template.json
- Matches actual plugin location and code default behavior
- Ensures web-ui-info plugin is available by default on fresh installs

* fix(config): Improve config save error handling

- Make load_config() failure non-fatal in save_raw_file_content
  - Wrapped reload in try-except to prevent save failures when reload fails
  - File save is atomic and successful even if reload fails
  - Logs warning when reload fails but doesn't fail the operation

- Improve error messages in API endpoints
  - Added detailed error logging with full traceback for debugging
  - Extract specific error messages from ConfigError exceptions
  - Include config_path in error messages when available
  - Provide fallback messages for empty error strings

- Enhance frontend error handling
  - Check response status before parsing JSON
  - Better handling of non-JSON error responses
  - Fallback error messages if error details are missing

Fixes issue where 'Error saving config.json: an error occured' was
shown even when the file was saved successfully but reload failed.

---------

Co-authored-by: Chuck <chuck@example.com>
This commit is contained in:
Chuck
2025-12-27 18:00:32 -05:00
committed by GitHub
parent f412350110
commit b0d65581df
3 changed files with 129 additions and 10 deletions

View File

@@ -218,16 +218,27 @@ function saveMainConfig() {
},
body: JSON.stringify(config)
})
.then(response => response.json())
.then(response => {
// Check if response is OK before parsing JSON
if (!response.ok) {
// Try to parse error response as JSON, fallback to status text
return response.json().then(data => {
throw new Error(data.message || response.statusText);
}).catch(() => {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
});
}
return response.json();
})
.then(data => {
if (data.status === 'success') {
showNotification('config.json saved successfully!', 'success');
} else {
showNotification('Error saving config.json: ' + data.message, 'error');
showNotification('Error saving config.json: ' + (data.message || 'Unknown error'), 'error');
}
})
.catch(error => {
showNotification('Error saving config.json: ' + error.message, 'error');
showNotification('Error saving config.json: ' + (error.message || 'An error occurred'), 'error');
});
} catch (e) {
showNotification('Invalid JSON: ' + e.message, 'error');
@@ -254,16 +265,27 @@ function saveSecretsConfig() {
},
body: JSON.stringify(config)
})
.then(response => response.json())
.then(response => {
// Check if response is OK before parsing JSON
if (!response.ok) {
// Try to parse error response as JSON, fallback to status text
return response.json().then(data => {
throw new Error(data.message || response.statusText);
}).catch(() => {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
});
}
return response.json();
})
.then(data => {
if (data.status === 'success') {
showNotification('config_secrets.json saved successfully!', 'success');
} else {
showNotification('Error saving config_secrets.json: ' + data.message, 'error');
showNotification('Error saving config_secrets.json: ' + (data.message || 'Unknown error'), 'error');
}
})
.catch(error => {
showNotification('Error saving config_secrets.json: ' + error.message, 'error');
showNotification('Error saving config_secrets.json: ' + (error.message || 'An error occurred'), 'error');
});
} catch (e) {
showNotification('Invalid JSON: ' + e.message, 'error');