Skip to content

Commit

Permalink
Pass correct field name to exception and message (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfaticaearnin authored and shauheen committed May 8, 2018
1 parent d9d1216 commit ae66210
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Microsoft.ML/TextLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void SetCustomStringFromType(bool useHeader, string separator,
{
var mappingAttr = field.GetCustomAttribute<ColumnAttribute>();
if(mappingAttr == null)
throw Contracts.ExceptParam(nameof(field.Name), " is missing ColumnAttribute");
throw Contracts.ExceptParam(field.Name, $"{field.Name} is missing ColumnAttribute");

schemaBuilder.AppendFormat("col={0}:{1}:{2} ",
mappingAttr.Name ?? field.Name,
Expand Down
13 changes: 13 additions & 0 deletions test/Microsoft.ML.Tests/TextLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.ML.Runtime.Api;
using Microsoft.ML.Runtime.Data;
using Microsoft.ML.TestFramework;
using System;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -219,6 +220,13 @@ public void CanSuccessfullyTrimSpaces()
}
}

[Fact]
public void ThrowsExceptionWithPropertyName()
{
Exception ex = Assert.Throws<ArgumentOutOfRangeException>( () => new TextLoader<ModelWithoutColumnAttribute>("fakefile.txt") );
Assert.StartsWith("String1 is missing ColumnAttribute", ex.Message);
}

public class QuoteInput
{
[Column("0")]
Expand Down Expand Up @@ -254,5 +262,10 @@ public class Input
[Column("1")]
public float Number1;
}

public class ModelWithoutColumnAttribute
{
public string String1;
}
}
}

0 comments on commit ae66210

Please sign in to comment.