-
Notifications
You must be signed in to change notification settings - Fork 203
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
MAYA-108586: Keep the TF_ERROR message format consistence with TF_WARN and TF_STATUS #1386
MAYA-108586: Keep the TF_ERROR message format consistence with TF_WARN and TF_STATUS #1386
Conversation
…N and TF_STATUS by only displaying the commentary string describing the diagnostic message.
@@ -107,7 +107,7 @@ void UsdMayaDiagnosticDelegate::IssueError(const TfError& err) | |||
// In addition, always display the full call site for errors by going | |||
// through _FormatDiagnostic. | |||
if (ArchIsMainThread()) { | |||
MGlobal::displayError(_FormatDiagnostic(err)); | |||
MGlobal::displayError(err.GetCommentary().c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do a fix inside of _FormatDiagnostic? If we fall, into the else then it will still print all the info (function/line/file) for error/status/warning. How about inside of _FormatDiagnostic you use if DEBUG check to print all info and in release only the commentary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seando-adsk Yeah, I thought about doing it that way but then not all the developers work in DEBUG. :) I myself most of the time work in RelWithDebInfo and barely ever bother with Debug.
The only other option would be to introduce an ENV variable to control this behaviour but again this could be controversial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But at least having it in DEBUG would provide an option to show all the info (file/function/line). With your change the only way to get that is to not be in the main thread, which I don't know how/why we wouldn't be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I don't have a strong preference but do people really need this? Why stop at "Errors"? What about Warnings?
For example, I see in many places in our code based people tend to use TF_WARN when checking for object validation.
if (shaderInstance == nullptr) {
TF_WARN("Failed to create shader instance for %s", nodeId.asChar());
break;
}
@@ -68,7 +74,8 @@ static MString _FormatDiagnostic(const TfDiagnosticBase& d) | |||
d.GetContext().GetFunction(), | |||
d.GetContext().GetLine(), | |||
d.GetContext().GetFile()); | |||
return msg.c_str(); | |||
|
|||
return TfGetEnvSetting(MAYAUSD_SHOW_FULL_DIAGNOSTICS) ? msg.c_str() : d.GetCommentary().c_str(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the time we will not be in full diagnostics mode. With the current code structure, we will always generate a full string. String operations are costly, how about we insert if/else condition and only generate msg string when needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes agreed. I also wonder about the need to check this new env var on every call for _FormatDiagnostic(). Do we need to be able to modify this env var during a Maya run? How about just getting this var once into a static variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kxl-adsk @seando-adsk I agree with you that std::string allocation can be costly and am very well aware of them. But the cost here is super minimal. I honestly don't believe we don't need to worry about operation costs in here. We can discuss this internally if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is status / warning / error reporting, I agree with Hamed and would not expect this to be high-frequency code, therefore performance isn't too much of a concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now with the extra file path parsing above, I would really like to see this code turned into an if/else condition as Krystian suggests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be happy to see the profiler results to understand where we hit this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a small comment but other than this looks good to me.
@@ -68,7 +74,8 @@ static MString _FormatDiagnostic(const TfDiagnosticBase& d) | |||
d.GetContext().GetFunction(), | |||
d.GetContext().GetLine(), | |||
d.GetContext().GetFile()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should strip off the path from this and leave only the filename? Isn't part of the problem that we are leaking our paths from the build VMs. I would again suggest that in Debug you leave it alone, but in RelWithDebInfo you strip it. Our Debug builds are never shipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't part of the problem that we are leaking our paths from the build VMs
We are not leaking our paths based on the new changes made in this PR. TF Error/Warning/Status are now show only the code commentary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But a user can enable the new env var and then they will see all the paths from our VMs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not create a simple regex to strip everything before maya-usd/src?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will strip everything before maya-usd:
Before:
S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp
After:
maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp
const std::string msg = TfStringPrintf( | ||
"%s -- %s in %s at line %zu of %s", | ||
d.GetCommentary().c_str(), | ||
TfDiagnosticMgr::GetCodeName(d.GetDiagnosticCode()).c_str(), | ||
d.GetContext().GetFunction(), | ||
d.GetContext().GetLine(), | ||
d.GetContext().GetFile()); | ||
filterFilePath.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter the file path so it discards everything before the project name (maya-usd
).
e.g
Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp
std::string filterFilePath { d.GetContext().GetFile() }; | ||
filterFilePath = filterFilePath.substr(filterFilePath.find("maya-usd")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find() returns npos (-1) if not found, so what if someone clones the repo at a root dir (or names it something other than maya-usd) what does substr(-1) give?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O.K. Yes, if people clone the project to some other names then this code won't do what is supposed to do.
I thought of a better solution where I convert the file path to a relative path. It looks even prettier than previous solution.
dd91145
e.g
// Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Albedo.png -- Coding Error in _LoadTexture at line 430 of Users\sabrih\Desktop\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for changing the msg if/else.
This PR keeps the TF_ERROR message format consistence with TF_WARN and TF_STATUS by displaying the by only displaying the commentary string.
Example below shows the case where an image resource is failed to created which results in a vague message to the user.
Before:
After the fix with a more meaningful message: