Catch throws in DeleteSymbol

DeleteSymbol may call SaveSymbol if the name is changed.  In this case,
SaveSymbol may throw back and needs to be caught

Fixes https://gitlab.com/kicad/code/kicad/issues/11566

(cherry picked from commit e05c8f8852)
This commit is contained in:
Seth Hillbrand 2022-05-06 16:12:25 -07:00
parent 717ea48395
commit 5cd3c07862
1 changed files with 25 additions and 4 deletions

View File

@ -973,11 +973,23 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
PROPERTIES properties;
properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
wxString errorMsg = _( "Error saving symbol %s to library '%s'." ) + wxS( "\n%s" );
// Delete the original symbol if the symbol name has been changed.
if( libSymbol->GetName() != originalSymbol->GetName() )
{
if( aLibTable->LoadSymbol( m_libName, originalSymbol->GetName() ) )
aLibTable->DeleteSymbol( m_libName, originalSymbol->GetName() );
// DeleteSymbol may throw
try
{
if( aLibTable->LoadSymbol( m_libName, originalSymbol->GetName() ) )
aLibTable->DeleteSymbol( m_libName, originalSymbol->GetName() );
}
catch( const IO_ERROR& ioe )
{
wxLogError( errorMsg, UnescapeString( originalSymbol->GetName() ), m_libName,
ioe.What() );
return false;
}
}
if( libSymbol->IsAlias() )
@ -1071,8 +1083,17 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
// Delete the original symbol if the symbol name has been changed.
if( libSymbol->GetName() != originalSymbol->GetName() )
{
if( aPlugin->LoadSymbol( aFileName, originalSymbol->GetName() ) )
aPlugin->DeleteSymbol( aFileName, originalSymbol->GetName(), &properties );
try
{
if( aPlugin->LoadSymbol( aFileName, originalSymbol->GetName() ) )
aPlugin->DeleteSymbol( aFileName, originalSymbol->GetName(), &properties );
}
catch( const IO_ERROR& ioe )
{
wxLogError( errorMsg, UnescapeString( originalSymbol->GetName() ), aFileName,
ioe.What() );
return false;
}
}
if( libSymbol->IsAlias() )