Ensure configuration validation provides clear, actionable error messages that guide users toward correct configuration. Validation should be comprehensive, checking not only types but also value ranges, logical consistency, and edge cases like undefined vs explicitly set values.
Ensure configuration validation provides clear, actionable error messages that guide users toward correct configuration. Validation should be comprehensive, checking not only types but also value ranges, logical consistency, and edge cases like undefined vs explicitly set values.
When validating configuration:
Example of good validation:
if (typeof rolloutStep === "number") {
const allowedSingleValues = [5, 10, 20, 25, 50, 100];
if (!allowedSingleValues.includes(rolloutStep)) {
diagnostics.errors.push(
`"containers.rollout_step_percentage" must be one of [5, 10, 20, 25, 50, 100], but got ${rolloutStep}`
);
}
} else if (Array.isArray(rolloutStep)) {
// Validate array elements and their sum
const sum = rolloutStep.reduce((acc, step) => acc + step, 0);
if (sum !== 100) {
diagnostics.errors.push(
`"containers.rollout_step_percentage" array elements must sum to 100, but values summed to "${sum}"`
);
}
} else {
diagnostics.errors.push(
`"containers.rollout_step_percentage" should be an array of numbers or a single number, but got ${JSON.stringify(rolloutStep)}`
);
}
This approach helps users understand exactly what went wrong and how to fix their configuration, reducing support burden and improving developer experience.
Enter the URL of a public GitHub repository