diff --git a/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs b/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs index 6cada95f53cc..4ba64ec95717 100644 --- a/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs +++ b/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs @@ -57,6 +57,38 @@ public void RqToSql_ThrowsArgumentNullException_WhenOptionsNull() Assert.Throws(() => PrqlCompiler.RqToSql("{}", null!)); } + [Fact] + public void Compile_ThrowsArgumentException_WhenQueryIsEmpty() + { + // Regression: previously `new ArgumentException(nameof(prqlQuery))` + // passed the parameter name into the message slot, leaving ParamName + // unset and the exception message as just "prqlQuery". + var ex = Assert.Throws(() => PrqlCompiler.Compile("")); + Assert.Equal("prqlQuery", ex.ParamName); + } + + [Fact] + public void PrqlToPl_ThrowsArgumentException_WhenQueryIsEmpty() + { + var ex = Assert.Throws(() => PrqlCompiler.PrqlToPl("")); + Assert.Equal("prqlQuery", ex.ParamName); + } + + [Fact] + public void PlToRq_ThrowsArgumentException_WhenJsonIsEmpty() + { + var ex = Assert.Throws(() => PrqlCompiler.PlToRq("")); + Assert.Equal("plJson", ex.ParamName); + } + + [Fact] + public void RqToSql_ThrowsArgumentException_WhenJsonIsEmpty() + { + var ex = Assert.Throws( + () => PrqlCompiler.RqToSql("", new PrqlCompilerOptions())); + Assert.Equal("rqJson", ex.ParamName); + } + [Fact] public void Compile_HandlesNonAsciiInput() { diff --git a/prqlc/bindings/dotnet/PrqlCompiler/PrqlCompiler.cs b/prqlc/bindings/dotnet/PrqlCompiler/PrqlCompiler.cs index ac70a7df5895..dc27544d9faa 100644 --- a/prqlc/bindings/dotnet/PrqlCompiler/PrqlCompiler.cs +++ b/prqlc/bindings/dotnet/PrqlCompiler/PrqlCompiler.cs @@ -18,10 +18,7 @@ public static partial class PrqlCompiler /// cannot be compiled. public static Result Compile(string prqlQuery) { - if (string.IsNullOrEmpty(prqlQuery)) - { - throw new ArgumentException(nameof(prqlQuery)); - } + ArgumentException.ThrowIfNullOrEmpty(prqlQuery); return Compile(prqlQuery, new PrqlCompilerOptions()); } @@ -37,11 +34,7 @@ public static Result Compile(string prqlQuery) /// cannot be compiled. public static Result Compile(string prqlQuery, PrqlCompilerOptions options) { - if (string.IsNullOrEmpty(prqlQuery)) - { - throw new ArgumentException(nameof(prqlQuery)); - } - + ArgumentException.ThrowIfNullOrEmpty(prqlQuery); ArgumentNullException.ThrowIfNull(options); var targetPtr = options.Target is null @@ -72,10 +65,7 @@ public static Result Compile(string prqlQuery, PrqlCompilerOptions options) /// https://docs.rs/prqlc/latest/ public static Result PrqlToPl(string prqlQuery) { - if (string.IsNullOrEmpty(prqlQuery)) - { - throw new ArgumentException(nameof(prqlQuery)); - } + ArgumentException.ThrowIfNullOrEmpty(prqlQuery); var nativeResult = PrqlToPlExtern(prqlQuery); return new Result(nativeResult); @@ -91,10 +81,7 @@ public static Result PrqlToPl(string prqlQuery) /// https://docs.rs/prqlc/latest/ public static Result PlToRq(string plJson) { - if (string.IsNullOrEmpty(plJson)) - { - throw new ArgumentException(nameof(plJson)); - } + ArgumentException.ThrowIfNullOrEmpty(plJson); var nativeResult = PlToRqExtern(plJson); return new Result(nativeResult); @@ -112,11 +99,7 @@ public static Result PlToRq(string plJson) /// https://docs.rs/prqlc/latest/ public static Result RqToSql(string rqJson, PrqlCompilerOptions options) { - if (string.IsNullOrEmpty(rqJson)) - { - throw new ArgumentException(nameof(rqJson)); - } - + ArgumentException.ThrowIfNullOrEmpty(rqJson); ArgumentNullException.ThrowIfNull(options); var targetPtr = options.Target is null