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

MAYA-108586: Keep the TF_ERROR message format consistence with TF_WARN and TF_STATUS #1386

Merged
merged 7 commits into from
May 13, 2021

Conversation

HamedSabri-adsk
Copy link
Contributor

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:

// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 
// Error: Failed verification: ' image ' -- Coding Error in _LoadTexture at line 422 of S:\jenkins\workspace\ecg-mayausd-full-2022-python3-windows\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp // 

After the fix with a more meaningful message:

// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Albedo.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Emissive.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Metallic.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Normal.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_AO.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Roughness.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVScreen_Albedo.png // 
// Error: Failed verification: ' image ' -- Unable to create an image from RetroTVScreen_Roughness.png // 

…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());
Copy link
Collaborator

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?

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.

Copy link
Collaborator

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.

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();

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

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 would be happy to see the profiler results to understand where we hit this issue.

Copy link

@kxl-adsk kxl-adsk left a 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());
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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());
Copy link
Contributor Author

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

Comment on lines 71 to 72
std::string filterFilePath { d.GetContext().GetFile() };
filterFilePath = filterFilePath.substr(filterFilePath.find("maya-usd"));
Copy link
Collaborator

@seando-adsk seando-adsk May 11, 2021

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@seando-adsk seando-adsk left a 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.

@HamedSabri-adsk HamedSabri-adsk added the ready-for-merge Development process is finished, PR is ready for merge label May 12, 2021
@kxl-adsk kxl-adsk merged commit 068786a into dev May 13, 2021
@kxl-adsk kxl-adsk deleted the sabrih/MAYA-108586/concistence_format_for_tf_errors branch May 13, 2021 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants