Skip to content

Commit

Permalink
nicer error messages on Tortoise/Git not found
Browse files Browse the repository at this point in the history
  • Loading branch information
VinsWorldcom committed Feb 18, 2022
1 parent 9009955 commit 281395a
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ std::wstring getCurrentFileDirectory()
return std::wstring(path);
}

std::wstring GetLastErrorString(DWORD errorCode)
{
std::wstring errorMsg(_T(""));
// Get the error message, if any.
// If both error codes (passed error n GetLastError) are 0, then return empty
if (errorCode == 0)
errorCode = GetLastError();
if (errorCode == 0)
return errorMsg; //No error message has been recorded

LPWSTR messageBuffer = nullptr;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, nullptr);

errorMsg += messageBuffer;

//Free the buffer.
LocalFree(messageBuffer);

return errorMsg;
}

///
/// Gets the path to the TortioseGit executable from the registry.
///
Expand Down Expand Up @@ -353,8 +375,12 @@ void ExecGitCommand(
command += TEXT( "\"" );

if ( !launchGit( command ) )
MessageBox( nppData._nppHandle, TEXT( "Could not launch Git." ),
{
std::wstring err = TEXT( "Could not launch Git.\n\n" );
err += GetLastErrorString(GetLastError());
MessageBox( nppData._nppHandle, err.c_str(),
TEXT( "Failed" ), ( MB_OK | MB_ICONWARNING | MB_APPLMODAL ) );
}

updatePanel();
}
Expand Down Expand Up @@ -396,8 +422,12 @@ void ExecTortoiseCommand(
command += TEXT( "\" /closeonend:2" );

if ( !launchGit( command ) )
MessageBox( nppData._nppHandle, TEXT( "Could not launch TortoiseGit." ),
{
std::wstring err = TEXT( "Could not launch TortoiseGit.\n\n" );
err += GetLastErrorString(GetLastError());
MessageBox( nppData._nppHandle, err.c_str(),
TEXT( "Failed" ), ( MB_OK | MB_ICONWARNING | MB_APPLMODAL ) );
}

updatePanel();
}
Expand Down

0 comments on commit 281395a

Please sign in to comment.