From 096d9fbbf9946d671f48e21b71d75c4b726584b6 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 3 May 2017 15:27:07 -0400 Subject: [PATCH] Pcbnew: continue loading footprints after first failure. The footprint library cache handler would throw an exception on the first error it encountered preventing all subsequent footprint files from being parsed even if there was nothing wrong with them. This commit queues errors until all of the footprint files in the folder have been parsed. Fixes lp:1416736 https://bugs.launchpad.net/kicad/+bug/1416736 --- common/footprint_info.cpp | 6 +++++- pcbnew/kicad_plugin.cpp | 29 ++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index c08667c22b..d5a652a47c 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -95,7 +95,11 @@ void FOOTPRINT_LIST::DisplayErrors( wxTopLevelWindow* aWindow ) while( auto error = PopError() ) { - msg += wxT( "

" ) + error->Problem() + wxT( "

" ); + wxString tmp = error->Problem(); + + // Preserve new lines in error messages so queued errors don't run together. + tmp.Replace( "\n", "
" ); + msg += wxT( "

" ) + tmp + wxT( "

" ); } dlg.AddHTML_Text( msg ); diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 3af27675c6..252ee30a2f 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -287,28 +287,43 @@ void FP_CACHE::Load() if( dir.GetFirst( &fpFileName, wildcard, wxDIR_FILES ) ) { + wxString cacheError; + do { // prepend the libpath into fullPath wxFileName fullPath( m_lib_path.GetPath(), fpFileName ); - FILE_LINE_READER reader( fullPath.GetFullPath() ); + // Queue I/O errors so only files that fail to parse don't get loaded. + try + { + FILE_LINE_READER reader( fullPath.GetFullPath() ); - m_owner->m_parser->SetLineReader( &reader ); + m_owner->m_parser->SetLineReader( &reader ); - std::string name = TO_UTF8( fullPath.GetName() ); - MODULE* footprint = (MODULE*) m_owner->m_parser->Parse(); + std::string name = TO_UTF8( fullPath.GetName() ); + MODULE* footprint = (MODULE*) m_owner->m_parser->Parse(); - // The footprint name is the file name without the extension. - footprint->SetFPID( LIB_ID( fullPath.GetName() ) ); - m_modules.insert( name, new FP_CACHE_ITEM( footprint, fullPath ) ); + // The footprint name is the file name without the extension. + footprint->SetFPID( LIB_ID( fullPath.GetName() ) ); + m_modules.insert( name, new FP_CACHE_ITEM( footprint, fullPath ) ); + } + catch( const IO_ERROR& ioe ) + { + if( !cacheError.IsEmpty() ) + cacheError += "\n\n"; + cacheError += ioe.What(); + } } while( dir.GetNext( &fpFileName ) ); // Remember the file modification time of library file when the // cache snapshot was made, so that in a networked environment we will // reload the cache as needed. m_mod_time = GetLibModificationTime(); + + if( !cacheError.IsEmpty() ) + THROW_IO_ERROR( cacheError ); } }