From 5fa0d5e030c74fe617b5dcd2685b066bac6f0366 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Sun, 24 Jan 2010 21:05:46 -0500 Subject: [PATCH] better debugging when can't open streams --- db/extsort.cpp | 2 +- tools/dump.cpp | 2 +- util/assert_util.cpp | 9 +++++++++ util/assert_util.h | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/db/extsort.cpp b/db/extsort.cpp index 08b343a1b50..beddc744068 100644 --- a/db/extsort.cpp +++ b/db/extsort.cpp @@ -113,7 +113,7 @@ namespace mongo { ofstream out; out.open( file.c_str() , ios_base::out | ios_base::binary ); - uassert( 10051 , (string)"couldn't open file: " + file , out.good() ); + ASSERT_STREAM_GOOD( 10051 , (string)"couldn't open file: " + file , out ); int num = 0; for ( InMemory::iterator i=_cur->begin(); i != _cur->end(); i++ ){ diff --git a/tools/dump.cpp b/tools/dump.cpp index 4cbd2e12f3f..a310e19782e 100644 --- a/tools/dump.cpp +++ b/tools/dump.cpp @@ -39,7 +39,7 @@ public: ofstream out; out.open( outputFile.string().c_str() , ios_base::out | ios_base::binary ); - uassert( 10262 , "couldn't open file" , out.good() ); + ASSERT_STREAM_GOOD( 10262 , "couldn't open file" , out ); ProgressMeter m( conn( true ).count( coll.c_str() , BSONObj() , QueryOption_SlaveOk ) ); diff --git a/util/assert_util.cpp b/util/assert_util.cpp index d1d85b2e155..55e1056f16a 100644 --- a/util/assert_util.cpp +++ b/util/assert_util.cpp @@ -72,6 +72,15 @@ namespace mongo { throw MsgAssertionException(msgid, msg); } + void streamNotGood( int code , string msg , std::ios& myios ){ + stringstream ss; + // errno might not work on all systems for streams + // if it doesn't for a system should deal with here + ss << msg << " stream invalie: " << OUTPUT_ERRNO; + throw UserException( code , ss.str() ); + } + + boost::mutex *Assertion::_mutex = new boost::mutex(); string Assertion::toString() { diff --git a/util/assert_util.h b/util/assert_util.h index ccb60a019bf..af1183a82c5 100644 --- a/util/assert_util.h +++ b/util/assert_util.h @@ -173,6 +173,10 @@ namespace mongo { #define ASSERT_ID_DUPKEY 11000 + void streamNotGood( int code , string msg , std::ios& myios ); + +#define ASSERT_STREAM_GOOD(msgid,msg,stream) (void)( (!!((stream).good())) || (mongo::streamNotGood(msgid, msg, stream), 0) ) + } // namespace mongo #define BOOST_CHECK_EXCEPTION( expression ) \