mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-18 15:45:03 +00:00
Configs are not decoded as well as validated by io-ts. Improvements to config validation, error messages, and TSafeRegex type.
This commit is contained in:
parent
2163d43dd1
commit
242bfe2b39
5 changed files with 223 additions and 74 deletions
|
@ -5,7 +5,7 @@ import { fold } from "fp-ts/lib/Either";
|
|||
import { PathReporter } from "io-ts/lib/PathReporter";
|
||||
import { availablePlugins } from "./plugins/availablePlugins";
|
||||
import { ZeppelinPlugin } from "./plugins/ZeppelinPlugin";
|
||||
import { validateStrict } from "./validatorUtils";
|
||||
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
||||
|
||||
const pluginNameToClass = new Map<string, typeof ZeppelinPlugin>();
|
||||
for (const pluginClass of availablePlugins) {
|
||||
|
@ -29,8 +29,8 @@ const globalConfigRootSchema = t.type({
|
|||
const partialMegaTest = t.partial({ name: t.string });
|
||||
|
||||
export function validateGuildConfig(config: any): string[] | null {
|
||||
const rootErrors = validateStrict(partialGuildConfigRootSchema, config);
|
||||
if (rootErrors) return rootErrors;
|
||||
const validationResult = decodeAndValidateStrict(partialGuildConfigRootSchema, config);
|
||||
if (validationResult instanceof StrictValidationError) return validationResult.getErrors();
|
||||
|
||||
if (config.plugins) {
|
||||
for (const [pluginName, pluginOptions] of Object.entries(config.plugins)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue