-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve errors for configs #637
Conversation
const paramsMessage = yamlDiffPatch("", {}, params); | ||
return `${color.yellow(instancePath)} ${ | ||
const prev = errors[i - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think prevError
would be better naming
return ""; | ||
} | ||
|
||
return `${instancePath === "" ? "" : `${color.yellow(instancePath)} `}${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably intancePath && color.yellow...
would be simpler? Or you have other reason to use ternary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter forbids using strings in the places where bool is expected to prevent unexpected behavior and to be more explicit about what exactly the check is checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because e.g. sometimes empty string is valid and you want to get rid of only undefined case
message ?? "" | ||
}\n${paramsMessage}`; | ||
}${paramsMessage === "" ? "" : `\n${paramsMessage}`}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
}) | ||
.filter((s) => { | ||
return ( | ||
s !== "" && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s && s !== "must match..."
return ( | ||
s !== "" && | ||
s !== "must match exactly one schema in oneOf\npassingSchemas: null\n" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if error messafe in ajv changes in the next version? Probably we can specify this explicitly in ajv error message if possible and refactor this as a shared const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the error changes then user will start seeing a new useless error, I am removing it here only because it's useless. I don't think moving it to const will help, but probably writing a test could, but I think writing a test for this would be too much, this bit is not so important
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can move it to const just for little bit of documentation purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But can you control this error on ajv? E.g. intercept it before error reaches the user. For example in js-client i use zod which allows me to intercept errors by filtering their codes and classes, change their message and even silence them.
Zod error API.
Because if i understand the code correctly, you want to prevent certain kind of errors from getting in user console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe possible using this https://ajv.js.org/packages/ajv-errors.html
not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can give it a try sooner or later with TODO and separate task. Dunno how hard would be to rewrite such places (if it even possible).
@@ -277,6 +287,9 @@ export function getReadonlyConfigInitFunction< | |||
getSchemaDirPath, | |||
} = options; | |||
|
|||
// every config schema has a version property by convention | |||
// eslint-disable-next-line | |||
const latestConfigVersion = latestSchema.properties.version.const as string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain this conversion a bit. Can't we extend schema type somehow with this? What is causing the need to do the conversion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually do extend schema, so it's impossible to pass pass a schema to this function that doesn't have version. But for some reason ajv types are not perfect in this sence and they don't produce correct results. I will improve comment to explains this a bit better. If you have nothing interesting to do you can to resolve as well, I wasnt' able to do it in a clean way
No description provided.