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
This commit is contained in:
Seth Hillbrand 2022-05-06 16:12:25 -07:00
parent 485e89f7a5
commit e05c8f8852
1 changed files with 25 additions and 4 deletions

View File

@ -959,12 +959,24 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
PROPERTIES properties;
properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, wxEmptyString );
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() )
{
// 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() )
{
@ -1053,10 +1065,19 @@ 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() )
{
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() )
{