mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Add simple validators to config
This commit is contained in:
3 files changed
+131
-3
No files matched your search
@@ -530,12 +530,13 @@ export class Config<
|
||||
if (!def) {
|
||||
throw new InvalidField(`No field named '${name}'`);
|
||||
}
|
||||
|
||||
this._checkAccess(name, def, remote, ConfigAccess.write, true);
|
||||
if (remote !== this.location) {
|
||||
this._checkAccess(name, def, this.location, ConfigAccess.write, true);
|
||||
}
|
||||
|
||||
// Empty strings are treates as null
|
||||
// Empty strings are treat as null
|
||||
if (value === "") {
|
||||
value = null;
|
||||
}
|
||||
@@ -576,6 +577,14 @@ export class Config<
|
||||
throw new InvalidValue(`Expected type of ${name} to be ${def.type}, not ${basicType(value)}`);
|
||||
}
|
||||
|
||||
if (def.extendedValidation) {
|
||||
try {
|
||||
def.extendedValidation(value, this);
|
||||
} catch (err: any) {
|
||||
throw new InvalidValue(`Failed validation of ${name}: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
this._set(name, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user