Skip to content

Commit

Permalink
Merge pull request #53 from RabotaRu/syntax-error
Browse files Browse the repository at this point in the history
Добавлен вывод информации об критических ошибках загрузки на главный экран
  • Loading branch information
rpiontik authored Apr 11, 2022
2 parents 96d8333 + ceabd3c commit 3116ccf
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 58 deletions.
48 changes: 29 additions & 19 deletions src/components/Problems/Problems.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<template>
<v-container>
<v-tabs v-model="currentTab">
<v-tab v-for="tab in problems" :key="tab.title" ripple>
{{ tab.title }}
</v-tab>
</v-tabs>
<ul v-if="problems.length" style="margin-top: 16px">
<template v-for="problem in problems[currentTab].problems">
<li :key="problem.route">
<router-link v-if="!problem.target"
:to="problem.route">{{problem.title}}
</router-link>
<a v-else :href="problem.route" :target="problem.target">
{{problem.title}}
</a>
</li>
</template>
</ul>
</v-container>
<div>
<v-container>
<v-tabs v-model="currentTab">
<v-tab v-for="tab in problems" :key="tab.title" ripple>
{{ tab.title }}
</v-tab>
</v-tabs>
<ul v-if="problems.length" style="margin-top: 16px">
<template v-for="problem in problems[currentTab].problems">
<li :key="problem.route">
<a v-if="problem.target === 'plugin'" @click="onGoto(problem.route)">
{{problem.title}}
</a>
<router-link v-else-if="!problem.target"
:to="problem.route">{{problem.title}}
</router-link>
<a v-else :href="problem.route" :target="problem.target">
{{problem.title}}
</a>
</li>
</template>
</ul>
</v-container>
</div>
</template>

<script>
export default {
name: 'Problems',
methods: {
onGoto(route) {
window.$PAPI.goto(route);
}
},
computed: {
problems() {
const tabs = {};
Expand Down
10 changes: 8 additions & 2 deletions src/components/Root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
</v-navigation-drawer>
<plugin-init v-if="isNotInited"/>
<v-content v-else v-show="!isLoading" style="min-height:100%" class="router-view">
<router-view/>
<problems v-if="isCriticalError"></problems>
<router-view v-else/>
</v-content>
<v-progress-circular
v-show="isLoading"
Expand All @@ -77,6 +78,7 @@
import Menu from "./Menu";
import PluginInit from '../idea/components/Init.vue'
import Problems from './Problems/Problems.vue'
const minDrawerSize = 200;
const defaultDrawerSize = 300;
Expand All @@ -85,7 +87,8 @@ export default {
name: 'Root',
components: {
Menu,
PluginInit
PluginInit,
Problems
},
mounted() {
const el = this.$refs.drawer.$el;
Expand Down Expand Up @@ -156,6 +159,9 @@ export default {
},
isNotInited() {
return this.isPlugin && this.$store.state.notInited;
},
isCriticalError() {
return this.isPlugin && this.$store.state.criticalError;
}
},
data() {
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import PlantUML from "./components/Schema/PlantUML";


window.Vue = Vue;
window.Router = router;

Vue.use(Vuex);
Vue.use(Vuetify);
Expand Down
56 changes: 26 additions & 30 deletions src/manifest/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ const parser = {
this.docs(item, baseURI);
}
},
//Регистрирует ошибку
// e - объект ошибки
// uri - источник ошибки
registerError(e, uri) {
const errorPath = `$errors/requests/${new Date().getTime()}`;
this.pushToMergeMap(errorPath, null, uri);
// eslint-disable-next-line no-console
console.error(e, `Ошибка запроса [${errorPath}:${uri}]`, e);
let errorType = (() => {
switch (e.name) {
case 'YAMLSyntaxError':
case 'YAMLSemanticError':
return "syntax";
default:
return 'net';
}
})();

this.onError && this.onError(errorType, {
uri,
error: e
});
},
// Сохраняет в карте склеивания данные
pushToMergeMap(path, source, location) {
if (path && path.split('/').length > 3) return;
Expand Down Expand Up @@ -160,16 +183,7 @@ const parser = {
context.node[context.property] = this.merge(context.node[context.property], response.data, URI, path);
this.touchProjects(URI);
})
.catch((e) => {
const errorPath = `$errors/requests/${new Date().getTime()}`;
// eslint-disable-next-line no-console
console.error(e, `Ошибка запроса (3) [${errorPath}:${URI}]`, e);
this.pushToMergeMap(errorPath, null, URI);
this.onError && this.onError('net', {
uri: URI,
error: e
});
})
.catch((e) => this.registerError(e, URI))
.finally(() => this.decReqCounter())
}
},
Expand All @@ -196,16 +210,7 @@ const parser = {
});
})
// eslint-disable-next-line no-console
.catch((e) => {
const errorPath = `$errors/requests/${new Date().getTime()}`;
// eslint-disable-next-line no-console
console.error(e, `Ошибка запроса (4) [${errorPath}:${URI}]`, e);
this.pushToMergeMap(errorPath, null, URI);
this.onError && this.onError('net', {
uri: URI,
error: e
});
})
.catch((e) => this.registerError(e, URI))
.finally(() => this.decReqCounter())
}
},
Expand Down Expand Up @@ -251,16 +256,7 @@ const parser = {
});
})
// eslint-disable-next-line no-console
.catch((e) => {
const errorPath = `$errors/requests/${new Date().getTime()}`;
// eslint-disable-next-line no-console
console.error(e, `Ошибка запроса (5) [${errorPath}:${uri}]`, e);
this.pushToMergeMap(errorPath, null, uri);
this.onError && this.onError('net', {
uri,
error: e
});
})
.catch((e) => this.registerError(e, uri))
.finally(() => {
this.decReqCounter();
});
Expand Down
3 changes: 2 additions & 1 deletion src/manifest/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default {

// manifest - манифест
expandAll(mainfest) {
[
mainfest
&& [
"docs", "components", "datasets",
"contexts", "aspects"
].forEach((section) => this.expandSection(mainfest[section]));
Expand Down
33 changes: 27 additions & 6 deletions src/storage/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default {
// Движок для рендеринга
renderCore: 'graphviz',
// Признак инциализации проекта в плагине
notInited: null
notInited: null,
// Признак критической проблемы
criticalError: null
},

mutations: {
Expand All @@ -44,6 +46,8 @@ export default {
state.available_projects = {};
state.projects = {};
state.last_changes = {};
state.notInited = null;
state.criticalError = null;
},
setManifest(state, value) {
state.manifest = value;
Expand Down Expand Up @@ -75,6 +79,9 @@ export default {
setNoInited(state, value) {
state.notInited = value;
},
setCriticalError(state, value) {
state.criticalError = value;
}
},

actions: {
Expand All @@ -97,17 +104,31 @@ export default {
context.commit('appendProblems',
query.expression(query.problems())
.evaluate(parser.manifest[manifest_parser.MODE_AS_IS]) || []);
if (!Object.keys(context.state.manifest || {}).length && (context.state.problems ||[]).length) {
context.commit('setCriticalError', true);
}
};
parser.onStartReload = () => {
context.commit('setNoInited', false);
context.commit('setIsReloading', true);
}
parser.onError = (action, data) => {
if (
(data.uri === consts.plugin.ROOT_MANIFEST)
&& (data.error.toString().slice(0, 17) !== "YAMLSemanticError")
) {
context.commit('setNoInited', true);
if (action === 'syntax') {
const problem = {
problem: "Ошибки синтаксиса",
route: (data.error.config || {url: data.uri}).url
};
if (process.env.VUE_APP_DOCHUB_MODE === "plugin") {
problem.target = "plugin";
problem.title = `${data.uri.slice(19)} [${data.error}]`;
} else {
problem.target = "_blank";
problem.title = `${data.uri} [${data.error}]`;
}
context.commit('appendProblems', [problem]);

} else if (data.uri === consts.plugin.ROOT_MANIFEST) {
context.commit('setNoInited', true);
} else {
context.commit('appendProblems', [{
problem: "Сетевые ошибки",
Expand Down

0 comments on commit 3116ccf

Please sign in to comment.