@@ -85,6 +85,21 @@ mongoc_cluster_fetch_stream_pooled (mongoc_cluster_t *cluster,
85
85
bool reconnect_ok ,
86
86
bson_error_t * error );
87
87
88
+
89
+ static const char *
90
+ get_command_name (const bson_t * command )
91
+ {
92
+ bson_iter_t iter ;
93
+
94
+ if (!bson_iter_init (& iter , command ) ||
95
+ !bson_iter_next (& iter )) {
96
+ return NULL ;
97
+ }
98
+
99
+ return bson_iter_key (& iter );
100
+ }
101
+
102
+
88
103
/*
89
104
*--------------------------------------------------------------------------
90
105
*
@@ -115,6 +130,7 @@ _mongoc_cluster_run_command (mongoc_cluster_t *cluster,
115
130
int32_t msg_len ;
116
131
bson_t reply_local ;
117
132
char ns [MONGOC_NAMESPACE_MAX ];
133
+ char error_message [sizeof error -> message ];
118
134
119
135
ENTRY ;
120
136
@@ -141,8 +157,16 @@ _mongoc_cluster_run_command (mongoc_cluster_t *cluster,
141
157
_mongoc_rpc_gather (& rpc , & ar );
142
158
_mongoc_rpc_swab_to_le (& rpc );
143
159
144
- if (!mongoc_stream_writev (stream , (mongoc_iovec_t * )ar .data , ar .len ,
145
- cluster -> sockettimeoutms )) {
160
+ if (!_mongoc_stream_writev_full (stream , (mongoc_iovec_t * )ar .data , ar .len ,
161
+ cluster -> sockettimeoutms , error )) {
162
+ /* add info about the command to writev_full's error message */
163
+ bson_snprintf (error_message ,
164
+ sizeof error -> message ,
165
+ "Failed to send \"%s\" command with database \"%s\": %s\n" ,
166
+ get_command_name (command ),
167
+ db_name ,
168
+ error -> message );
169
+ bson_strncpy (error -> message , error_message , sizeof error -> message );
146
170
GOTO (failure );
147
171
}
148
172
0 commit comments