Skip to content
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

Option to get callstack from property function exception #8151

Open
rainersigwald opened this issue Nov 9, 2022 · 1 comment
Open

Option to get callstack from property function exception #8151

rainersigwald opened this issue Nov 9, 2022 · 1 comment
Labels

Comments

@rainersigwald
Copy link
Member

I'm not sure if there's a way to get more info from the exception [thrown by a property function] without debugging into the intrinsic method. @rainersigwald might know of some msbuild magic here.

Originally posted by @benvillalobos in dotnet/sdk#28971 (comment)

@rainersigwald
Copy link
Member Author

Looks like this is happening here, where we look at a bunch of Exception.Messages when we should use the ones with stacks (maybe configurably):

// Exceptions coming from the actual function called are wrapped in a TargetInvocationException
catch (TargetInvocationException ex)
{
// We ended up with something other than a function expression
string partiallyEvaluated = GenerateStringOfMethodExecuted(_expression, objectInstance, _methodMethodName, args);
if (options.HasFlag(ExpanderOptions.LeavePropertiesUnexpandedOnError))
{
// If the caller wants to ignore errors (in a log statement for example), just return the partially evaluated value
return partiallyEvaluated;
}
ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", partiallyEvaluated, ex.InnerException.Message.Replace("\r\n", " "));
return null;
}
// Any other exception was thrown by trying to call it
catch (Exception ex) when (!ExceptionHandling.NotExpectedFunctionException(ex))
{
// If there's a :: in the expression, they were probably trying for a static function
// invocation. Give them some more relevant info in that case
if (s_invariantCompareInfo.IndexOf(_expression, "::", CompareOptions.OrdinalIgnoreCase) > -1)
{
ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionStaticMethodSyntax", _expression, ex.Message.Replace("Microsoft.Build.Evaluation.IntrinsicFunctions.", "[MSBuild]::"));
}
else
{
// We ended up with something other than a function expression
string partiallyEvaluated = GenerateStringOfMethodExecuted(_expression, objectInstance, _methodMethodName, args);
ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidFunctionPropertyExpression", partiallyEvaluated, ex.Message);
}
return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants