core: ConfigArgService.validateRequiredFields() fails checking ShippingEligibilityChecker with required arg
See original GitHub issueIt seems saving a shipping method with an assigned ShippingEligibilityChecker which has at least one arg with required:true
and containing a type which can’t be parsed by JSON.parse() always fails with the configurable-argument-is-required
error.
I think the problem is the validateRequiredFields
method, which checks the value with:
let val: unknown;
if (inputArg) {
try {
val = JSON.parse(inputArg?.value);
} catch (e) {
// ignore
}
}
if (val == null) {
throw new UserInputError('error.configurable-argument-is-required', {
name,
});
}
As inputArg.value
is a string in my case, JSON.parse(inputArg?.value)
throws an error (which is ignored), val == null
evaluates to true and the validation fails.
Possible types seem to be from ConfigArgType
: 'string' | 'int' | 'float' | 'boolean' | 'datetime' | 'ID'
. So my proposition is to change the error-evaluation to something like !inputArg || inputArg.value === null || input.value === ""
to cover all types (not exactly sure on this, peer review please: are all type covered correctly?).
Code here: config-arg.service.ts#L91
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
That’s true, but purely for the purpose of checking for “emptiness” in required fields, I think an empty string check is sufficient.
If we then want to also validate the actual data of each field, then that’s another issue and would warrant its own feature request.
I think Int, Float, Bool and Null work with JSON.parse(), the others are basically strings and should be checked if they are not empty.