Skip to content

TextLoader exception message missing parameter name #33 #65

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

Merged
merged 1 commit into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Pass correct field name to exception and message
  • Loading branch information
mfatica committed May 8, 2018
commit ded585373c0617d68e373412c950a6b9d26bd850
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;
}
}
}