Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing error handling for unknown modules in simulator #224

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/CreateConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<v-card color="danger">
<v-card-title>Couldn't load config</v-card-title>
<v-card-text>
<pre><code>{{ errors }}</code></pre>
<pre style="white-space: pre-wrap;"><code>{{ errors }}</code></pre>
</v-card-text>
<v-card-actions>
<v-btn color="primary" @click="resetDialog()">OK</v-btn>
Expand All @@ -79,13 +79,14 @@
</template>

<script setup lang="ts">
import {computed, ref} from "vue";
import { computed, ref, inject, defineEmits } from "vue";
import {useEvbcStore} from "@/store/evbc";
import {storeToRefs} from "pinia";
import yaml from "js-yaml";
import Ajv from "ajv";
import {EverestConfig} from "@/modules/evbc";
import {urlToPublicAsset} from "@/utils";
import EVBackendClient from "@/modules/evbc/client";

enum ComponentStates {
DEFAULT,
Expand All @@ -103,6 +104,7 @@ const {available_configs} = storeToRefs(evbcStore);
const configContent = ref<EverestConfig>(null);
const errors = ref<string>(null);
const showErrorDialog = computed<boolean>(() => !!errors.value);
const evbc = inject<EVBackendClient>('evbc') as EVBackendClient;

function onAcceptBtnClick() {
if (validateConfigName() === true) {
Expand Down Expand Up @@ -188,8 +190,15 @@ async function getConfigJsonSchema(): Promise<object> {
async function parseConfig(content: string): Promise<{ errors: string, config: EverestConfig }> {
try {
const config = yaml.load(content);
// catch schema/syntax errors in the config
const validationResult = await validateConfigContent(config);
if (validationResult === true) {
// Catch logical errors in the config
try {
evbc.create_config_model(configName.value, config as EverestConfig);
} catch (e) {
return { errors: e.toString(), config: null };
}
return {errors: null, config: config as EverestConfig};
} else {
return {errors: validationResult, config: null};
Expand Down
10 changes: 5 additions & 5 deletions src/modules/evbc/config_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class EVConfigModel {

_add_module_instance(type: string, id: string, config?: EverestModuleConfig, view_config?: ModuleViewConfig): number {
if (!(type in this._module_definitions)) {
throw Error(`Invalid module type: ${type}`);
throw Error(`Invalid module type: ${type}. Are you running in simulator mode? If yes, this likely means this version of the Admin Panel in simulator mode doesn't support this module yet. Make sure you are running the correct admin panel or connect to a live instance.`);
}
if (Object.values(this._instances).filter((value) => value.id === id).length) {
throw Error(`Module instance with id: ${module.id} already exists`);
Expand Down Expand Up @@ -361,12 +361,12 @@ class EVConfigModel {
_validate_connection(conn: Connection) {
const prov_id = conn.providing_instance_id;
if (!(prov_id in this._instances)) {
throw Error(`Providing instance with instance id ${prov_id} does not exist`);
throw Error(`Providing instance with instance id ${prov_id} does not exist. Are you running in simulator mode? If yes, this likely means this version of the Admin Panel in simulator mode doesn't support this interface yet. Make sure you are running the correct admin panel or connect to a live instance.`);
}

const req_id = conn.requiring_instance_id;
if (!(req_id in this._instances)) {
throw Error(`Requiring instance with instance id ${req_id} does not exist`);
throw Error(`Requiring instance with instance id ${req_id} does not exist. Are you running in simulator mode? If yes, this likely means this version of the Admin Panel in simulator mode doesn't support this interface yet. Make sure you are running the correct admin panel or connect to a live instance.`);
}

const prov_module = this._instances[prov_id].type;
Expand All @@ -377,13 +377,13 @@ class EVConfigModel {

if (!(conn.providing_impl_name in prov_manifest.provides)) {
throw Error(
`Providing module of type "${prov_module}" does not provide an implementation named "${conn.providing_impl_name}"`
`Providing module of type "${prov_module}" does not provide an implementation named "${conn.providing_impl_name}. Are you running in simulator mode? If yes, this likely means this version of the Admin Panel in simulator mode doesn't support this yet. Make sure you are running the correct admin panel or connect to a live instance."`
);
}

if (!(conn.requirement_name in req_manifest.requires)) {
throw Error(
`Requiring module of type "${req_module}" does not have an requirement called "${conn.requirement_name}"`
`Requiring module of type "${req_module}" does not have an requirement called "${conn.requirement_name}. Are you running in simulator mode? If yes, this likely means this version of the Admin Panel in simulator mode doesn't support this yet. Make sure you are running the correct admin panel or connect to a live instance."`
);
}

Expand Down
Loading