handle utf8 errors better in js, try to convert to js error SERVER-1063 SERVER-1056

This commit is contained in:
Eliot Horowitz
2010-04-28 15:04:22 -04:00
parent e3fa699ae4
commit 071f4015b4
2 changed files with 52 additions and 6 deletions

View File

@@ -38,6 +38,12 @@
}
namespace mongo {
class InvalidUTF8Exception : public UserException {
public:
InvalidUTF8Exception() : UserException( 9006 , "invalid utf8" ){
}
};
string trim( string s ){
while ( s.size() && isspace( s[0] ) )
@@ -501,7 +507,7 @@ namespace mongo {
jsval v;
if ( JS_GetPendingException( _context , &v ) )
cout << "\t why: " << toString( v ) << endl;
throw UserException( 9006 , "invalid utf8" );
throw InvalidUTF8Exception();
}
assert( s );
@@ -982,7 +988,15 @@ namespace mongo {
return JS_TRUE;
}
jsval val = c.toval( e );
jsval val;
try {
val = c.toval( e );
}
catch ( InvalidUTF8Exception& e ){
JS_LeaveLocalRootScope( cx );
JS_ReportError( cx , "invalid utf8" );
return JS_FALSE;
}
assert( ! holder->_inResolve );
holder->_inResolve = true;