semantic-kernel
semantic-kernel copied to clipboard
Throw ArgumentNullExceptions for null arguments
Motivation and Context
Use ArgumentNullException as devs expect, and avoid exception-related work when not throwing.
Description
.NET developers expect that passing null erroneously to a method will result in an ArgumentNullException, but currently it's resulting in a custom ValidationException.
There are also places where string interpolation is being used to create the error message; the work and allocation associated with that interpolation is going to happen regardless of whether the exception is thrown or not.
Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with
dotnet format
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone :smile:
LGTM.
💡 A code weaver like Fody.NullGuard or a Roslyn code generator might be helpful in replacing all those runtime null
checks.
@stephentoub looks like there are some conflicts that need to be resolved before merging.
looks like there are some conflicts that need to be resolved before merging.
Done. Thanks.