From 01882d31036cf6c5653de7b89d4f6f898b16655d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 13 Aug 2018 23:26:38 +0100 Subject: [PATCH] Add more/better error messages for file i/o problems. --- common/richio.cpp | 20 +++++--------------- eeschema/libarch.cpp | 10 ++++++++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/common/richio.cpp b/common/richio.cpp index 2f32a245a2..a8eefce9af 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -514,20 +514,15 @@ void STRING_FORMATTER::StripUseless() //--------------------------------------------- -FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName, - const wxChar* aMode, char aQuoteChar ): +FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName, const wxChar* aMode, + char aQuoteChar ): OUTPUTFORMATTER( OUTPUTFMTBUFZ, aQuoteChar ), m_filename( aFileName ) { m_fp = wxFopen( aFileName, aMode ); if( !m_fp ) - { - wxString msg = wxString::Format( - _( "cannot open or save file \"%s\"" ), - m_filename.GetData() ); - THROW_IO_ERROR( msg ); - } + THROW_IO_ERROR( std::strerror( errno ) ); } @@ -540,13 +535,8 @@ FILE_OUTPUTFORMATTER::~FILE_OUTPUTFORMATTER() void FILE_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) { - if( 1 != fwrite( aOutBuf, aCount, 1, m_fp ) ) - { - wxString msg = wxString::Format( - _( "error writing to file \"%s\"" ), - m_filename.GetData() ); - THROW_IO_ERROR( msg ); - } + if( fwrite( aOutBuf, (unsigned) aCount, 1, m_fp ) != 1 ) + THROW_IO_ERROR( std::strerror( errno ) ); } diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index 0e0c207b3f..bc52f17630 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -148,10 +148,16 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) { archLib->Save( false ); } - catch( ... /* IO_ERROR ioe */ ) + catch( const IO_ERROR& ioe ) { errorMsg.Printf( _( "Failed to save symbol library file \"%s\"" ), aFileName ); - DisplayError( this, errorMsg ); + DisplayErrorMessage( this, errorMsg, ioe.What() ); + return false; + } + catch( std::exception& error ) + { + errorMsg.Printf( _( "Failed to save symbol library file \"%s\"" ), aFileName ); + DisplayErrorMessage( this, errorMsg, error.what() ); return false; }