Skip to content

Commit

Permalink
chore: added errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Sep 23, 2024
1 parent 041f7d0 commit 622f4fe
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/helpers/validator.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { Value } from "@sinclair/typebox/value";
import { Value, ValueError } from "@sinclair/typebox/value";
import { envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types";

export function validateAndDecodeSchemas(env: object, rawSettings: object) {
const errors: object[] = [];
const errors: ValueError[] = [];
if (!envValidator.test(env)) {
for (const error of envValidator.errors(env)) {
const errorMessage = { path: error.path, message: error.message, value: error.value };
console.error(errorMessage);
errors.push(errorMessage);
console.error(error);
errors.push(error);
}
}
const envDecoded = Value.Decode(envSchema, env || {});

const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings;
if (!pluginSettingsValidator.test(settings)) {
for (const error of pluginSettingsValidator.errors(settings)) {
const errorMessage = { path: error.path, message: error.message, value: error.value };
console.error(errorMessage);
errors.push(errorMessage);
console.error(error);
errors.push(error);
}
}

Expand Down

0 comments on commit 622f4fe

Please sign in to comment.