Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ₯… Catch error caused by empty config

Alicia Sykes9e6fb17d9329
diff --git a/src/components/Configuration/JsonEditor.vue b/src/components/Configuration/JsonEditor.vue
index 0267d2a2..b2bdbe72 100644
--- a/src/components/Configuration/JsonEditor.vue
+++ b/src/components/Configuration/JsonEditor.vue
@@ -116,7 +116,8 @@ export default {
},
mounted() {
const jsonData = { ...this.config };
- jsonData.sections = jsonData.sections.map(({ filteredItems, ...section }) => section);
+ jsonData.sections = (jsonData.sections || []).map(({ filteredItems, ...section }) => section);
+ if (!jsonData.pageInfo) jsonData.pageInfo = { title: 'Dashy' };
this.jsonData = jsonData;
if (!this.allowWriteToDisk) this.saveMode = 'local';
},
diff --git a/src/store.js b/src/store.js
index 57710c0d..0fa33019 100644
--- a/src/store.js
+++ b/src/store.js
@@ -44,6 +44,12 @@ const {
CRITICAL_ERROR_MSG,
} = Keys;
+const emptyConfig = {
+ appConfig: {},
+ pageInfo: { title: 'Dashy' },
+ sections: [],
+};
+
const store = new Vuex.Store({
state: {
config: {}, // The current config being used, and rendered to the UI
@@ -335,7 +341,7 @@ const store = new Vuex.Store({
data = yaml.load(response.data);
} catch (parseError) {
commit(CRITICAL_ERROR_MSG, `Failed to parse YAML: ${parseError.message}`);
- return {};
+ return { ...emptyConfig };
}
// Replace missing root properties with empty objects
if (!data.appConfig) data.appConfig = {};
@@ -357,7 +363,7 @@ const store = new Vuex.Store({
} else {
commit(CRITICAL_ERROR_MSG, `Failed to fetch configuration: ${fetchError.message}`);
}
- return {};
+ return { ...emptyConfig };
}
},
/**
@@ -368,6 +374,7 @@ const store = new Vuex.Store({
*/
async [INITIALIZE_CONFIG]({ commit, state }, subConfigId) {
const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
+
commit(SET_IS_USING_LOCAL_CONFIG, false);
if (!subConfigId) { // Use root config as config
commit(SET_CONFIG, rootConfig);
@@ -396,7 +403,7 @@ const store = new Vuex.Store({
if (!subConfigPath) {
commit(CRITICAL_ERROR_MSG, `Unable to find config for '${subConfigId}'`);
- return null;
+ return { ...emptyConfig };
}
axios.get(subConfigPath).then((response) => {
@@ -428,7 +435,7 @@ const store = new Vuex.Store({
commit(CRITICAL_ERROR_MSG, `Unable to load config from '${subConfigPath}'`, err);
});
}
- return null;
+ return { ...emptyConfig };
},
},
modules: {},