if https:// GET fails, report the URL

This commit is contained in:
Dick Hollenbeck 2013-10-03 10:12:25 -05:00
parent 44ca3530b0
commit 8234966a3a
2 changed files with 34 additions and 22 deletions

View File

@ -115,31 +115,29 @@ struct IO_ERROR // : std::exception
* @param aMsg is error text that will be streamed through wxString.Printf() * @param aMsg is error text that will be streamed through wxString.Printf()
* using the format string IO_FORMAT above. * using the format string IO_FORMAT above.
*/ */
IO_ERROR( const char* aThrowersFile, explicit IO_ERROR( const char* aThrowersFile,
const char* aThrowersLoc, const char* aThrowersLoc,
const wxString& aMsg ) const wxString& aMsg )
{ {
init( aThrowersFile, aThrowersLoc, aMsg ); init( aThrowersFile, aThrowersLoc, aMsg );
} }
#if !wxCHECK_VERSION(2, 9, 0) explicit IO_ERROR( const char* aThrowersFile,
// 2.9.0 and greater provide a wxString() constructor taking "const char*" whereas
// 2.8 did not. In 2.9.x this IO_ERROR() constructor uses that wxString( const char* )
// constructor making this here constructor ambiguous with the IO_ERROR()
// taking the wxString.
IO_ERROR( const char* aThrowersFile,
const char* aThrowersLoc, const char* aThrowersLoc,
const std::string& aMsg ) const std::string& aMsg )
{ {
init( aThrowersFile, aThrowersLoc, wxString::FromUTF8( aMsg.c_str() ) ); init( aThrowersFile, aThrowersLoc, wxString::FromUTF8( aMsg.c_str() ) );
} }
#endif
/** explicit IO_ERROR( const char* aThrowersFile,
* handles the case where _() is passed as aMsg. const char* aThrowersLoc,
*/ const char* aMsg )
IO_ERROR( const char* aThrowersFile, {
init( aThrowersFile, aThrowersLoc, wxString::FromUTF8( aMsg ) );
}
/// handle the case where _() is passed as aMsg.
explicit IO_ERROR( const char* aThrowersFile,
const char* aThrowersLoc, const char* aThrowersLoc,
const wxChar* aMsg ) const wxChar* aMsg )
{ {

View File

@ -56,9 +56,9 @@
using namespace std; using namespace std;
typedef boost::ptr_map<std::string, wxZipEntry> MODULE_MAP; typedef boost::ptr_map<string, wxZipEntry> MODULE_MAP;
typedef MODULE_MAP::iterator MODULE_ITER; typedef MODULE_MAP::iterator MODULE_ITER;
typedef MODULE_MAP::const_iterator MODULE_CITER; typedef MODULE_MAP::const_iterator MODULE_CITER;
/** /**
@ -166,11 +166,17 @@ void GITHUB_PLUGIN::cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR )
{ {
if( !m_cache || m_lib_path != aLibraryPath ) if( !m_cache || m_lib_path != aLibraryPath )
{ {
//D(printf("%s: this:%p m_lib_path:'%s' aLibraryPath:'%s'\n", __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );) // operator==( wxString, wxChar* ) does not exist, construct wxString once here.
const wxString kicad_mod( wxT( "kicad_mod" ) );
//D(printf("%s: this:%p m_lib_path:'%s' aLibraryPath:'%s'\n", __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );)
delete m_cache; delete m_cache;
m_cache = new GH_CACHE(); m_cache = new GH_CACHE();
// INIT_LOGGER( "/tmp", "test.log" );
remote_get_zip( aLibraryPath ); remote_get_zip( aLibraryPath );
// UNINIT_LOGGER();
m_lib_path = aLibraryPath; m_lib_path = aLibraryPath;
wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() ); wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() );
@ -182,11 +188,11 @@ void GITHUB_PLUGIN::cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR )
while( ( entry = zis.GetNextEntry() ) != NULL ) while( ( entry = zis.GetNextEntry() ) != NULL )
{ {
wxFileName fn( entry->GetName() ); wxFileName fn( entry->GetName() ); // chop long name into parts
if( fn.GetExt() == wxT( "kicad_mod" ) ) if( fn.GetExt() == kicad_mod )
{ {
string fp_name = TO_UTF8( fn.GetName() ); string fp_name = TO_UTF8( fn.GetName() ); // omit extension & path
m_cache->insert( fp_name, entry ); m_cache->insert( fp_name, entry );
} }
@ -253,9 +259,17 @@ void GITHUB_PLUGIN::remote_get_zip( const wxString& aRepoURL ) throw( IO_ERROR )
// 4 lines, using SSL, top that. // 4 lines, using SSL, top that.
} }
catch( std::exception& e ) catch( boost::system::system_error& e )
{ {
THROW_IO_ERROR( e.what() ); // https "GET" has faild, report this to API caller.
wxString fmt( _( "Cannot GET zip: '%s'\nfor lib-path: '%s'.\nWhat: '%s'" ) );
string msg = StrPrintf( TO_UTF8( fmt ),
zip_url.c_str(),
TO_UTF8( aRepoURL ),
e.what() );
THROW_IO_ERROR( msg );
} }
} }