Skip to content

Commit f0beeee

Browse files
mfaticaearnineerhardt
authored andcommitted
Pass correct field name to exception and message (dotnet#65)
1 parent 46841bc commit f0beeee

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Microsoft.ML/TextLoader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void SetCustomStringFromType(bool useHeader, string separator,
5555
{
5656
var mappingAttr = field.GetCustomAttribute<ColumnAttribute>();
5757
if(mappingAttr == null)
58-
throw Contracts.ExceptParam(nameof(field.Name), " is missing ColumnAttribute");
58+
throw Contracts.ExceptParam(field.Name, $"{field.Name} is missing ColumnAttribute");
5959

6060
schemaBuilder.AppendFormat("col={0}:{1}:{2} ",
6161
mappingAttr.Name ?? field.Name,

test/Microsoft.ML.Tests/TextLoaderTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.ML.Runtime.Api;
88
using Microsoft.ML.Runtime.Data;
99
using Microsoft.ML.TestFramework;
10+
using System;
1011
using Xunit;
1112
using Xunit.Abstractions;
1213

@@ -219,6 +220,13 @@ public void CanSuccessfullyTrimSpaces()
219220
}
220221
}
221222

223+
[Fact]
224+
public void ThrowsExceptionWithPropertyName()
225+
{
226+
Exception ex = Assert.Throws<ArgumentOutOfRangeException>( () => new TextLoader<ModelWithoutColumnAttribute>("fakefile.txt") );
227+
Assert.StartsWith("String1 is missing ColumnAttribute", ex.Message);
228+
}
229+
222230
public class QuoteInput
223231
{
224232
[Column("0")]
@@ -254,5 +262,10 @@ public class Input
254262
[Column("1")]
255263
public float Number1;
256264
}
265+
266+
public class ModelWithoutColumnAttribute
267+
{
268+
public string String1;
269+
}
257270
}
258271
}

0 commit comments

Comments
 (0)