Skip to content

Respect Marked exception during model loading. #2574

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

Conversation

Ivanidzo4ka
Copy link
Contributor

address #2567

@Ivanidzo4ka Ivanidzo4ka requested review from eerhardt, TomFinley and yaeldekel and removed request for eerhardt February 15, 2019 20:01
@codecov
Copy link

codecov bot commented Feb 15, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@b2587fa). Click here to learn what that means.
The diff coverage is 45.45%.

@@            Coverage Diff            @@
##             master    #2574   +/-   ##
=========================================
  Coverage          ?    71.5%           
=========================================
  Files             ?      801           
  Lines             ?   142036           
  Branches          ?    16151           
=========================================
  Hits              ?   101561           
  Misses            ?    36003           
  Partials          ?     4472
Flag Coverage Δ
#Debug 71.5% <45.45%> (?)
#production 67.79% <47.36%> (?)
#test 85.56% <33.33%> (?)

catch (Exception ex)
{
if (ex.InnerException != null && ex.InnerException.IsMarked())
throw Contracts.Except(ex, "Error during class instantiation");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually add value? Why not just let the original exception be thrown? It will have the stacktrace of where it came from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of Invoke call. If anything happens inside it, we got TargetInvocationException and original exception would be inside InnerException.

Copy link
Member

@eerhardt eerhardt Feb 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least catch (TargetInvocationException ex) here then. #Resolved

if (ex.InnerException != null && ex.InnerException.IsMarked())
throw Contracts.Except(ex, "Error during class instantiation");
else
throw ex;
Copy link
Member

@eerhardt eerhardt Feb 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please never do this.

throw; is what you want.

What you are doing is cutting off the stack trace from the original exception, which contains valuable information when debugging. #Resolved

@@ -257,8 +257,10 @@ public static TransformerChain<ITransformer> LoadFrom(IHostEnvironment env, Stre
ModelLoadContext.LoadModel<TransformerChain<ITransformer>, SignatureLoadModel>(env, out var transformerChain, rep, LoaderSignature);
return transformerChain;
}
catch
catch (FormatException ex)
Copy link
Member

@eerhardt eerhardt Feb 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this much better. #Closed

@@ -69,6 +69,7 @@ private static ITransformer Create(IHostEnvironment env, ModelLoadContext ctx)
var contractName = ctx.LoadString();

var composition = env.GetCompositionContainer();
Contracts.CheckValue(composition,nameof(composition));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is being deleted with #2569

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand.
I'm just trying to resolve this comment from TestCustomTrasformer :
we should have a common mechanism that will make sure this is 'our' exception thrown.

Only way I know how to do that is to check was exception marked or not.
Currently composition is null, and in next line it throws NullReference. Which is unmarked, and in order to make it marked, I need to run check on it.

{
if (!ex.IsMarked())
throw ex;
Copy link
Member

@eerhardt eerhardt Feb 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again here - throw;. #Resolved

@@ -69,9 +69,10 @@ public void TestCustomTransformer()
TestEstimatorCore(customEst, data);
Assert.True(false, "Cannot work without MEF injection");
}
catch (Exception)
catch (Exception ex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to be the specific type of exception we expect?

And possibly adding a check for the message - since I'm sure it will just be InvalidOperationException.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Ivanidzo4ka !!

@TomFinley TomFinley merged commit 3456bb3 into dotnet:master Feb 16, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants