From 11be5d6f1d2e16a12f6cc98a524e281c915bdf45 Mon Sep 17 00:00:00 2001 From: John Beard Date: Mon, 11 Dec 2023 19:47:06 +0000 Subject: [PATCH] Improve error handling when reading test board data --- qa/pcbnew_utils/board_file_utils.cpp | 14 +++++++++++++- qa/pcbnew_utils/board_test_utils.cpp | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/qa/pcbnew_utils/board_file_utils.cpp b/qa/pcbnew_utils/board_file_utils.cpp index f25abdef4d..df6864edcd 100644 --- a/qa/pcbnew_utils/board_file_utils.cpp +++ b/qa/pcbnew_utils/board_file_utils.cpp @@ -93,7 +93,7 @@ std::unique_ptr ReadBoardItemFromStream( std::istream& aStream ) std::unique_ptr ReadBoardFromFileOrStream( const std::string& aFilename, - std::istream& aFallback ) + std::istream& aFallback ) { std::istream* in_stream = nullptr; std::ifstream file_stream; @@ -106,6 +106,12 @@ std::unique_ptr ReadBoardFromFileOrStream( const std::string& aFilename, else { file_stream.open( aFilename ); + + if( !file_stream.is_open() ) + { + return nullptr; + } + in_stream = &file_stream; } @@ -127,6 +133,12 @@ std::unique_ptr ReadFootprintFromFileOrStream( const std::string& aFi else { file_stream.open( aFilename ); + + if( !file_stream.is_open() ) + { + return nullptr; + } + in_stream = &file_stream; } diff --git a/qa/pcbnew_utils/board_test_utils.cpp b/qa/pcbnew_utils/board_test_utils.cpp index f7acd3052a..76653153b5 100644 --- a/qa/pcbnew_utils/board_test_utils.cpp +++ b/qa/pcbnew_utils/board_test_utils.cpp @@ -86,7 +86,17 @@ void LoadBoard( SETTINGS_MANAGER& aSettingsManager, const wxString& aRelPath, else if( legacyProject.Exists() ) aSettingsManager.LoadProject( legacyProject.GetFullPath() ); - aBoard = ReadBoardFromFileOrStream( boardPath ); + BOOST_TEST_MESSAGE( "Loading board file: " << boardPath ); + + try { + aBoard = ReadBoardFromFileOrStream( boardPath ); + } + catch( const IO_ERROR& ioe ) + { + BOOST_TEST_ERROR( ioe.What() ); + } + + BOOST_REQUIRE( aBoard ); if( projectFile.Exists() || legacyProject.Exists() ) aBoard->SetProject( &aSettingsManager.Prj() );