Skip to content

Commit 254a316

Browse files
authored
Message related to missing models improved in DNNImageFeaturizers. (#2812)
* error msg improved * Fixing the line number with addition of new code * adding space and removing path Co-Authored-By: Anipik <[email protected]>
1 parent 485c99e commit 254a316

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/Microsoft.ML.Core/Utilities/Contracts.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,11 @@ public static void CheckIO(this IExceptionContext ctx, bool f, string msg)
737737
if (!f)
738738
throw ExceptIO(ctx, msg);
739739
}
740-
740+
public static void CheckIO(this IExceptionContext ctx, bool f, string msg, params object[] args)
741+
{
742+
if (!f)
743+
throw ExceptIO(ctx, msg, args);
744+
}
741745
#if !CPUMATH_INFRASTRUCTURE
742746
/// <summary>
743747
/// Check state of the host and throw exception if host marked to stop all exection.

src/Microsoft.ML.OnnxTransformer/OnnxTransform.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private OnnxTransformer(IHostEnvironment env, Options options, byte[] modelBytes
165165
if (modelBytes == null)
166166
{
167167
Host.CheckNonWhiteSpace(options.ModelFile, nameof(options.ModelFile));
168-
Host.CheckUserArg(File.Exists(options.ModelFile), nameof(options.ModelFile));
168+
Host.CheckIO(File.Exists(options.ModelFile), "Model file {0} does not exists.", options.ModelFile);
169169
Model = new OnnxModel(options.ModelFile, options.GpuDeviceId, options.FallbackToCpu);
170170
}
171171
else
@@ -588,4 +588,4 @@ public override SchemaShape GetOutputSchema(SchemaShape inputSchema)
588588
return new SchemaShape(resultDic.Values);
589589
}
590590
}
591-
}
591+
}

test/Microsoft.ML.CodeAnalyzer.Tests/Code/ContractsCheckTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public async Task ContractsCheckFix()
125125
VerifyCS.Diagnostic(ContractsCheckAnalyzer.NameofDiagnostic.Rule).WithLocation(22, 39).WithArguments("CheckValue", "paramName", "\"noMatch\""),
126126
VerifyCS.Diagnostic(ContractsCheckAnalyzer.NameofDiagnostic.Rule).WithLocation(23, 53).WithArguments("CheckUserArg", "name", "\"chumble\""),
127127
VerifyCS.Diagnostic(ContractsCheckAnalyzer.NameofDiagnostic.Rule).WithLocation(24, 53).WithArguments("CheckUserArg", "name", "\"sp\""),
128-
new DiagnosticResult("CS1503", DiagnosticSeverity.Error).WithLocation("Test1.cs", 748, 91).WithMessage("Argument 2: cannot convert from 'Microsoft.ML.IHostEnvironment' to 'Microsoft.ML.IExceptionContext'"),
128+
new DiagnosticResult("CS1503", DiagnosticSeverity.Error).WithLocation("Test1.cs", 752, 91).WithMessage("Argument 2: cannot convert from 'Microsoft.ML.IHostEnvironment' to 'Microsoft.ML.IExceptionContext'"),
129129
},
130130
AdditionalReferences = { AdditionalMetadataReferences.RefFromType<Memory<int>>() },
131131
},
@@ -144,7 +144,7 @@ public async Task ContractsCheckFix()
144144
{
145145
VerifyCS.Diagnostic(ContractsCheckAnalyzer.ExceptionDiagnostic.Rule).WithLocation(8, 43).WithArguments("ExceptParam"),
146146
VerifyCS.Diagnostic(ContractsCheckAnalyzer.NameofDiagnostic.Rule).WithLocation(22, 39).WithArguments("CheckValue", "paramName", "\"noMatch\""),
147-
new DiagnosticResult("CS1503", DiagnosticSeverity.Error).WithLocation("Test1.cs", 748, 91).WithMessage("Argument 2: cannot convert from 'Microsoft.ML.IHostEnvironment' to 'Microsoft.ML.IExceptionContext'"),
147+
new DiagnosticResult("CS1503", DiagnosticSeverity.Error).WithLocation("Test1.cs", 752, 91).WithMessage("Argument 2: cannot convert from 'Microsoft.ML.IHostEnvironment' to 'Microsoft.ML.IExceptionContext'"),
148148
},
149149
},
150150
};

0 commit comments

Comments
 (0)