Skip to content
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

Final changes for parameter validation #7291

Merged
merged 8 commits into from
Sep 30, 2024

Conversation

sproutleaf
Copy link

@sproutleaf sproutleaf commented Sep 27, 2024

Addresses #7178

Changes:

  • Added parameter validation support for paletteLerp, see added paletteLerp #6960
  • Instead of using zod-validation-error library, prints error messages with custom logic catered towards beginners, and modified the tests accordingly.
  • Updated convert.js, to 1) ignore false duplicated definitions (i.e. what happened with createAudio), and 2) dedup when overloads of the same types exist
  • Some code cleanups, including deleting the outstanding TODO items that have been completed, deleting function printZodSchema that's only for debugging purposes, etc.

Screenshots of the change:

PR Checklist

@sproutleaf sproutleaf marked this pull request as ready for review September 27, 2024 03:03
}
}

return message;
Copy link
Contributor

@davepagurek davepagurek Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if we have enough info here to be able to log a link to the docs for the method the user tried to call? If the error is something like "Add more arguments", a link to the reference to see what's expected might be helpful. (Also not a blocker, but if it's possible to do, we can always make an issue for it and see if a community contributor is interested in taking it on)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point, thank you for the suggestion! I just added a commit that would append a documentation link to the end of the error message for cases where the user provided too few / too many arguments. I think ideally I'd want to also make sure that the link is both valid and reachable before appending, but feel like that could be a TODO later since p5 documentation follows a pretty standard format, and I don't know how adding an async function in the code would affect it. For now, I think this would suffice.

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, nice work!

Comment on lines 393 to 402
message = `Expected at least ${minArgs} argument${minArgs > 1 ? 's' : ''}, but received fewer. Please add more arguments!`;
break;
}
case 'invalid_type': {
message = buildTypeMismatchMessage(currentError.received, currentError.expected, currentError.path.join('.'));
break;
}
case 'too_big': {
const maxArgs = currentError.maximum;
message = `Expected at most ${maxArgs} argument${maxArgs > 1 ? 's' : ''}, but received more. Please delete some arguments!`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The messages probably should have the name of the function being called in there to help with identifying source of error, if it is not already part of the message.

The suggested fix likely need to be more of a suggestive tone as the suggested fix may not be the actual problem. ie. instead of "Please add/delete arguments" go with something more like "Did you forget to add an argument?"/"Removing some arguments may help", or the suggestion can be omitted as well in line with the current FES's behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@limzykenneth
Copy link
Member

For using the parameter validation throughout the code base, I mentioned not using p5._validateParameters() in individual functions but instead use the decorator pattern that adds the parameter validation feature on initialization: https://refactoring.guru/design-patterns/decorator. I am working on refactoring the initialization stuff at the moment so code there are changing, you may want to try out some proof of concept instead at this stage for this if it made sense.

@davepagurek
Copy link
Contributor

Also for reference, here was an issue where we talk in the comments about a decorator approach with some code examples: #6597

@limzykenneth
Copy link
Member

I think there's still some adjustment I would like to make to the messages but we can do that after phase two also has its messages.

@limzykenneth limzykenneth merged commit 34d41a5 into processing:dev-2.0 Sep 30, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants