Skip to content

Commit d2e972f

Browse files
committed
Update error message for failing to satisfy minimum wire version
1 parent 17eca57 commit d2e972f

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/libmongoc/src/mongoc/mongoc-topology-description.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,9 +1989,11 @@ _mongoc_topology_description_check_compatible (
19891989
MONGOC_ERROR_PROTOCOL,
19901990
MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION,
19911991
"Server at %s reports wire version %d, but this"
1992-
" version of libmongoc requires at least 3 (MongoDB 3.0)",
1992+
" version of libmongoc requires at least %d (MongoDB %s)",
19931993
sd->host.host_and_port,
1994-
sd->max_wire_version);
1994+
sd->max_wire_version,
1995+
WIRE_VERSION_MIN,
1996+
_mongoc_wire_version_to_server_version (WIRE_VERSION_MIN));
19951997
}
19961998
}
19971999
}

src/libmongoc/src/mongoc/mongoc-util-private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ _mongoc_bson_init_if_set (bson_t *bson);
100100
const char *
101101
_mongoc_bson_type_to_str (bson_type_t t);
102102

103+
const char *
104+
_mongoc_wire_version_to_server_version (int32_t version);
105+
103106
bool
104107
_mongoc_get_server_id_from_opts (const bson_t *opts,
105108
mongoc_error_domain_t domain,

src/libmongoc/src/mongoc/mongoc-util.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,48 @@ _mongoc_bson_type_to_str (bson_type_t t)
268268
}
269269

270270

271+
/* Refer to:
272+
* https://github.com/mongodb/specifications/blob/master/source/wireversion-featurelist.rst
273+
* and:
274+
* https://github.com/mongodb/mongo/blob/master/src/mongo/db/wire_version.h#L57
275+
*/
276+
const char *
277+
_mongoc_wire_version_to_server_version (int32_t version)
278+
{
279+
switch (version) {
280+
case 1:
281+
case 2:
282+
return "2.6";
283+
case 3:
284+
return "3.0";
285+
case 4:
286+
return "3.2";
287+
case 5:
288+
return "3.4";
289+
case 6:
290+
return "3.6";
291+
case 7:
292+
return "4.0";
293+
case 8:
294+
return "4.2";
295+
case 9:
296+
return "4.4";
297+
case 10:
298+
return "4.7";
299+
case 11:
300+
return "4.8";
301+
case 12:
302+
return "4.9";
303+
case 13:
304+
return "5.0";
305+
case 14:
306+
return "5.1";
307+
default:
308+
return "Unknown";
309+
}
310+
}
311+
312+
271313
/* Get "serverId" from opts. Sets *server_id to the serverId from "opts" or 0
272314
* if absent. On error, fills out *error with domain and code and return false.
273315
*/

0 commit comments

Comments
 (0)