@@ -124,9 +124,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doDropDatabase(Reference<ExtConnecti
124
124
return reply;
125
125
} catch (Error& e) {
126
126
// clang-format off
127
- reply->addDocument (BSON (" ok" << 1.0 <<
128
- " err" << e.what () <<
129
- " code" << e.code ()));
127
+ reply->setError (e);
130
128
// clang-format on
131
129
return reply;
132
130
}
@@ -187,16 +185,17 @@ struct GetlasterrorCmd {
187
185
try {
188
186
WriteResult res = wait (lastWrite);
189
187
bob.appendNumber (" n" , (long long )res.n ); // < FIXME: ???
190
- bob << " err" << BSONNULL << " ok" << 1.0 ;
188
+ bob << " $ err" << BSONNULL << " ok" << 1.0 ;
191
189
if (!res.upsertedOIDList .empty ()) {
192
190
bob.appendElements (DataValue::decode_key_part (res.upsertedOIDList [0 ]).wrap (" upserted" ));
193
191
}
194
192
if (res.type == WriteType::UPDATE) {
195
193
bob << " updatedExisting" << (res.nModified > 0 && res.upsertedOIDList .empty ());
196
194
}
197
195
} catch (Error& e) {
198
- bob.append (" err" , e.what ());
196
+ bob.append (" $ err" , e.name ());
199
197
bob.append (" code" , e.code ());
198
+ bob.append (" errmsg" , e.what ());
200
199
bob.appendNumber (" n" , (long long )0 );
201
200
bob.append (" ok" , 1.0 );
202
201
}
@@ -226,13 +225,10 @@ struct GetLogCmd {
226
225
static Future<Reference<ExtMsgReply>> call (Reference<ExtConnection> nmc,
227
226
Reference<ExtMsgQuery> query,
228
227
Reference<ExtMsgReply> reply) {
229
- bson::BSONObjBuilder bob;
230
228
231
229
if (query->ns .first != " admin" ) {
232
230
// clang-format off
233
- reply->addDocument ((bob << " ok" << 0.0 <<
234
- " errmsg" << " access denied; use admin db" <<
235
- " $err" << " access denied; use admin db" ).obj ());
231
+ reply->setError (access_denied_use_admin_db ());
236
232
// clang-format on
237
233
return reply;
238
234
}
@@ -283,15 +279,9 @@ struct ReplSetGetStatusCmd {
283
279
static Future<Reference<ExtMsgReply>> call (Reference<ExtConnection> nmc,
284
280
Reference<ExtMsgQuery> query,
285
281
Reference<ExtMsgReply> reply) {
286
- bson::BSONObjBuilder bob;
287
282
288
283
// FIXME: what do we really want to report here?
289
- bob.append (" ok" , 0.0 );
290
- bob.append (" errmsg" , " not really talking to mongodb" );
291
- bob.append (" $err" , " not really talking to mongodb" );
292
-
293
- reply->addDocument (bob.obj ());
294
-
284
+ reply->setError (not_really_talking_to_mongodb ());
295
285
return reply;
296
286
}
297
287
};
@@ -391,7 +381,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doDropCollection(Reference<ExtConnec
391
381
reply->addDocument (BSON (" ok" << 1.0 ));
392
382
return reply;
393
383
} catch (Error& e) {
394
- reply->addDocument ( BSON ( " ok " << 1.0 << " err " << e. what () << " code " << e. code ()) );
384
+ reply->setError (e );
395
385
return reply;
396
386
}
397
387
}
@@ -483,7 +473,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doRenameCollection(Reference<ExtConn
483
473
reply->addDocument (BSON (" ok" << 1.0 ));
484
474
return reply;
485
475
} catch (Error& e) {
486
- reply->addDocument ( BSON ( " ok " << 0.0 << " errmsg " << e. what () << " code " << e. code ()) );
476
+ reply->setError (e );
487
477
return reply;
488
478
}
489
479
}
@@ -518,7 +508,7 @@ ACTOR static Future<Reference<ExtMsgReply>> getStreamCount(Reference<ExtConnecti
518
508
reply->addDocument (BSON (" n" << (double )std::max<int64_t >(count - skip, 0 ) << " ok" << 1.0 ));
519
509
return reply;
520
510
} catch (Error& e) {
521
- reply->addDocument ( BSON ( " $err " << e. what () << " code " << e. code () << " ok " << 1.0 ) );
511
+ reply->setError (e );
522
512
reply->setResponseFlags (2 );
523
513
return reply;
524
514
}
@@ -632,10 +622,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doFindAndModify(Reference<ExtConnect
632
622
reply->addDocument (replyObj);
633
623
} catch (Error& e) {
634
624
// clang-format off
635
- reply->addDocument (BSON (" errmsg" << e.what () <<
636
- " $err" << e.what () <<
637
- " code" << e.code () <<
638
- " ok" << 1.0 ));
625
+ reply->setError (e);
639
626
// clang-format on
640
627
}
641
628
@@ -702,9 +689,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doDropIndexesActor(Reference<ExtConn
702
689
return reply;
703
690
} else {
704
691
// clang-format off
705
- reply->addDocument (BSON (" ok" << 0.0 <<
706
- " $err" << " 'index' must be a string or an object" <<
707
- " errmsg" << " 'index' must be a string or an object" ));
692
+ reply->setError (index_must_be_a_string_or_an_object ());
708
693
// clang-format on
709
694
return reply;
710
695
}
@@ -724,9 +709,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doDropIndexesActor(Reference<ExtConn
724
709
}
725
710
} catch (Error& e) {
726
711
// clang-format off
727
- reply->addDocument (BSON (" ok" << 0.0 <<
728
- " err" << e.what () <<
729
- " code" << e.code ()));
712
+ reply->setError (e);
730
713
// clang-format on
731
714
return reply;
732
715
}
@@ -767,10 +750,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doCreateIndexes(Reference<ExtConnect
767
750
reply->addDocument (BSON (" ok" << 1.0 ));
768
751
} catch (Error& e) {
769
752
// clang-format off
770
- reply->addDocument (BSON (" ok" << 0.0 <<
771
- " $err" << e.what () <<
772
- " errmsg" << e.what () <<
773
- " code" << e.code ()));
753
+ reply->setError (e);
774
754
// clang-format on
775
755
}
776
756
return reply;
@@ -917,7 +897,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doCreateCollection(Reference<ExtConn
917
897
reply->addDocument (BSON (" ok" << 1.0 ));
918
898
return reply;
919
899
} catch (Error& e) {
920
- reply->addDocument ( BSON ( " ok " << 1.0 << " err " << e. what () << " code " << e. code ()) );
900
+ reply->setError (e );
921
901
return reply;
922
902
}
923
903
}
@@ -945,11 +925,7 @@ ACTOR static Future<Reference<ExtMsgReply>> doGetKVStatusActor(Reference<ExtConn
945
925
<< vv.encode_value ().toString ()) /* bson::fromjson(vv.encode_value().c_str())*/ );
946
926
}
947
927
} catch (Error& e) {
948
- reply->addDocument (
949
- BSON (" ok" << 1.0 << " err"
950
- << " This command is supported only with version 3.0 and above of the KV Store, if you are using "
951
- " an older FDB version please use the fdbcli utility to check its status."
952
- << " code" << e.code ()));
928
+ reply->setError (unsupported_fdb_version_for_kvstatus ());
953
929
}
954
930
955
931
return reply;
@@ -1067,8 +1043,8 @@ ACTOR static Future<Reference<ExtMsgReply>> insertAndReply(Reference<ExtConnecti
1067
1043
for (int i = 0 ; i < docs.size (); i++) {
1068
1044
// clang-format off
1069
1045
arrayBuilder << BSON (" index" << i <<
1046
+ " $err" << e.name () <<
1070
1047
" code" << e.code () <<
1071
- " $err" << e.what () <<
1072
1048
" errmsg" << e.what ());
1073
1049
// clang-format on
1074
1050
}
@@ -1379,7 +1355,7 @@ ACTOR static Future<Reference<ExtMsgReply>> getStreamDistinct(Reference<ExtConne
1379
1355
// clang-format on
1380
1356
return reply;
1381
1357
} catch (Error& e) {
1382
- reply->addDocument ( BSON ( " $err " << e. what () << " code " << e. code () << " ok " << 1.0 ) );
1358
+ reply->setError (e );
1383
1359
reply->setResponseFlags (2 /* 0b0010*/ );
1384
1360
return reply;
1385
1361
}
0 commit comments