couchbase 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/CMakeLists.txt +3 -0
  4. data/ext/build_version.hxx.in +1 -1
  5. data/ext/cmake/CompilerWarnings.cmake +1 -0
  6. data/ext/cmake/PreventInSourceBuilds.cmake +4 -1
  7. data/ext/couchbase/bucket.hxx +28 -2
  8. data/ext/couchbase/cluster.hxx +8 -2
  9. data/ext/couchbase/couchbase.cxx +955 -511
  10. data/ext/couchbase/error_context/analytics.hxx +46 -0
  11. data/ext/couchbase/error_context/http.hxx +44 -0
  12. data/ext/couchbase/error_context/key_value.hxx +47 -0
  13. data/ext/couchbase/error_context/query.hxx +46 -0
  14. data/ext/couchbase/error_context/search.hxx +47 -0
  15. data/ext/couchbase/error_context/view.hxx +47 -0
  16. data/ext/couchbase/io/dns_codec.hxx +1 -2
  17. data/ext/couchbase/io/http_command.hxx +16 -3
  18. data/ext/couchbase/io/http_context.hxx +1 -1
  19. data/ext/couchbase/io/http_session.hxx +12 -6
  20. data/ext/couchbase/io/http_session_manager.hxx +25 -24
  21. data/ext/couchbase/io/mcbp_session.hxx +8 -2
  22. data/ext/couchbase/io/retry_context.hxx +1 -1
  23. data/ext/couchbase/operations/analytics_dataset_create.hxx +19 -12
  24. data/ext/couchbase/operations/analytics_dataset_drop.hxx +18 -10
  25. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +16 -10
  26. data/ext/couchbase/operations/analytics_dataverse_create.hxx +18 -11
  27. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +17 -11
  28. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +17 -10
  29. data/ext/couchbase/operations/analytics_index_create.hxx +17 -11
  30. data/ext/couchbase/operations/analytics_index_drop.hxx +16 -10
  31. data/ext/couchbase/operations/analytics_index_get_all.hxx +14 -10
  32. data/ext/couchbase/operations/analytics_link_connect.hxx +15 -9
  33. data/ext/couchbase/operations/analytics_link_disconnect.hxx +16 -10
  34. data/ext/couchbase/operations/bucket_create.hxx +33 -10
  35. data/ext/couchbase/operations/bucket_drop.hxx +9 -8
  36. data/ext/couchbase/operations/bucket_flush.hxx +8 -8
  37. data/ext/couchbase/operations/bucket_get.hxx +15 -10
  38. data/ext/couchbase/operations/bucket_get_all.hxx +14 -7
  39. data/ext/couchbase/operations/bucket_settings.hxx +16 -0
  40. data/ext/couchbase/operations/bucket_update.hxx +32 -10
  41. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +6 -6
  42. data/ext/couchbase/operations/collection_create.hxx +19 -13
  43. data/ext/couchbase/operations/collection_drop.hxx +18 -12
  44. data/ext/couchbase/operations/collections_manifest_get.hxx +5 -10
  45. data/ext/couchbase/operations/document_analytics.hxx +39 -17
  46. data/ext/couchbase/operations/document_append.hxx +5 -10
  47. data/ext/couchbase/operations/document_decrement.hxx +5 -10
  48. data/ext/couchbase/operations/document_exists.hxx +4 -6
  49. data/ext/couchbase/operations/document_get.hxx +6 -10
  50. data/ext/couchbase/operations/document_get_and_lock.hxx +4 -9
  51. data/ext/couchbase/operations/document_get_and_touch.hxx +4 -9
  52. data/ext/couchbase/operations/document_get_projected.hxx +21 -14
  53. data/ext/couchbase/operations/document_increment.hxx +5 -10
  54. data/ext/couchbase/operations/document_insert.hxx +5 -10
  55. data/ext/couchbase/operations/document_lookup_in.hxx +4 -9
  56. data/ext/couchbase/operations/document_mutate_in.hxx +7 -12
  57. data/ext/couchbase/operations/document_prepend.hxx +5 -10
  58. data/ext/couchbase/operations/document_query.hxx +45 -28
  59. data/ext/couchbase/operations/document_remove.hxx +5 -10
  60. data/ext/couchbase/operations/document_replace.hxx +5 -10
  61. data/ext/couchbase/operations/document_search.hxx +37 -16
  62. data/ext/couchbase/operations/document_touch.hxx +4 -9
  63. data/ext/couchbase/operations/document_unlock.hxx +4 -9
  64. data/ext/couchbase/operations/document_upsert.hxx +5 -10
  65. data/ext/couchbase/operations/document_view.hxx +29 -13
  66. data/ext/couchbase/operations/group_drop.hxx +7 -7
  67. data/ext/couchbase/operations/group_get.hxx +14 -10
  68. data/ext/couchbase/operations/group_get_all.hxx +14 -8
  69. data/ext/couchbase/operations/group_upsert.hxx +15 -9
  70. data/ext/couchbase/operations/http_noop.hxx +5 -5
  71. data/ext/couchbase/operations/mcbp_noop.hxx +3 -9
  72. data/ext/couchbase/operations/query_index_build_deferred.hxx +15 -9
  73. data/ext/couchbase/operations/query_index_create.hxx +16 -10
  74. data/ext/couchbase/operations/query_index_drop.hxx +16 -10
  75. data/ext/couchbase/operations/query_index_get_all.hxx +13 -7
  76. data/ext/couchbase/operations/role_get_all.hxx +14 -8
  77. data/ext/couchbase/operations/scope_create.hxx +19 -13
  78. data/ext/couchbase/operations/scope_drop.hxx +17 -11
  79. data/ext/couchbase/operations/scope_get_all.hxx +15 -10
  80. data/ext/couchbase/operations/search_get_stats.hxx +5 -5
  81. data/ext/couchbase/operations/search_index_analyze_document.hxx +25 -13
  82. data/ext/couchbase/operations/search_index_control_ingest.hxx +23 -11
  83. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +23 -11
  84. data/ext/couchbase/operations/search_index_control_query.hxx +23 -11
  85. data/ext/couchbase/operations/search_index_drop.hxx +22 -10
  86. data/ext/couchbase/operations/search_index_get.hxx +22 -10
  87. data/ext/couchbase/operations/search_index_get_all.hxx +13 -7
  88. data/ext/couchbase/operations/search_index_get_documents_count.hxx +24 -13
  89. data/ext/couchbase/operations/search_index_get_stats.hxx +16 -10
  90. data/ext/couchbase/operations/search_index_upsert.hxx +23 -11
  91. data/ext/couchbase/operations/user_drop.hxx +8 -8
  92. data/ext/couchbase/operations/user_get.hxx +14 -10
  93. data/ext/couchbase/operations/user_get_all.hxx +14 -8
  94. data/ext/couchbase/operations/user_upsert.hxx +15 -9
  95. data/ext/couchbase/operations/view_index_drop.hxx +7 -7
  96. data/ext/couchbase/operations/view_index_get.hxx +15 -9
  97. data/ext/couchbase/operations/view_index_get_all.hxx +15 -9
  98. data/ext/couchbase/operations/view_index_upsert.hxx +8 -8
  99. data/ext/couchbase/origin.hxx +1 -0
  100. data/ext/couchbase/platform/terminate_handler.cc +12 -8
  101. data/ext/couchbase/protocol/client_request.hxx +2 -1
  102. data/ext/couchbase/protocol/client_response.hxx +18 -15
  103. data/ext/couchbase/protocol/cmd_exists.hxx +1 -0
  104. data/ext/couchbase/protocol/cmd_get.hxx +1 -1
  105. data/ext/couchbase/protocol/cmd_mutate_in.hxx +3 -4
  106. data/ext/couchbase/protocol/enhanced_error_info.hxx +28 -0
  107. data/ext/couchbase/utils/connection_string.hxx +1 -1
  108. data/ext/couchbase/version.hxx +1 -1
  109. data/ext/extconf.rb +1 -1
  110. data/ext/test/test_native_binary_operations.cxx +18 -18
  111. data/ext/test/test_native_diagnostics.cxx +2 -2
  112. data/ext/test/test_native_trivial_crud.cxx +2 -2
  113. data/ext/third_party/json/include/tao/json/external/pegtl/internal/file_reader.hpp +1 -5
  114. data/lib/active_support/cache/couchbase_store.rb +362 -0
  115. data/lib/couchbase.rb +2 -0
  116. data/lib/couchbase/authenticator.rb +26 -0
  117. data/lib/couchbase/binary_collection.rb +1 -0
  118. data/lib/couchbase/bucket.rb +1 -0
  119. data/lib/couchbase/cluster.rb +51 -27
  120. data/lib/couchbase/collection.rb +19 -4
  121. data/lib/couchbase/collection_options.rb +10 -0
  122. data/lib/couchbase/configuration.rb +57 -0
  123. data/lib/couchbase/datastructures.rb +6 -0
  124. data/lib/couchbase/errors.rb +111 -3
  125. data/lib/couchbase/management.rb +27 -0
  126. data/lib/couchbase/management/bucket_manager.rb +9 -2
  127. data/lib/couchbase/management/collection_manager.rb +1 -1
  128. data/lib/couchbase/management/user_manager.rb +18 -2
  129. data/lib/couchbase/options.rb +33 -23
  130. data/lib/couchbase/railtie.rb +45 -0
  131. data/lib/couchbase/scope.rb +44 -3
  132. data/lib/couchbase/utils.rb +21 -0
  133. data/lib/couchbase/utils/time.rb +52 -0
  134. data/lib/couchbase/version.rb +1 -1
  135. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  136. metadata +19 -5
@@ -25,9 +25,7 @@ namespace couchbase::operations
25
25
  {
26
26
 
27
27
  struct remove_response {
28
- document_id id;
29
- std::uint32_t opaque;
30
- std::error_code ec{};
28
+ error_context::key_value ctx;
31
29
  std::uint64_t cas{};
32
30
  mutation_token token{};
33
31
  };
@@ -59,17 +57,14 @@ struct remove_request {
59
57
  };
60
58
 
61
59
  remove_response
62
- make_response(std::error_code ec, remove_request& request, remove_request::encoded_response_type&& encoded)
60
+ make_response(error_context::key_value&& ctx, remove_request& request, remove_request::encoded_response_type&& encoded)
63
61
  {
64
- remove_response response{ request.id, encoded.opaque(), ec };
65
- if (ec && response.opaque == 0) {
66
- response.opaque = request.opaque;
67
- }
68
- if (!ec) {
62
+ remove_response response{ ctx };
63
+ if (!response.ctx.ec) {
69
64
  response.cas = encoded.cas();
70
65
  response.token = encoded.body().token();
71
66
  response.token.partition_id = request.partition;
72
- response.token.bucket_name = response.id.bucket;
67
+ response.token.bucket_name = response.ctx.id.bucket;
73
68
  }
74
69
  return response;
75
70
  }
@@ -26,9 +26,7 @@ namespace couchbase::operations
26
26
  {
27
27
 
28
28
  struct replace_response {
29
- document_id id;
30
- std::uint32_t opaque;
31
- std::error_code ec{};
29
+ error_context::key_value ctx;
32
30
  std::uint64_t cas{};
33
31
  mutation_token token{};
34
32
  };
@@ -66,17 +64,14 @@ struct replace_request {
66
64
  };
67
65
 
68
66
  replace_response
69
- make_response(std::error_code ec, replace_request& request, replace_request::encoded_response_type&& encoded)
67
+ make_response(error_context::key_value&& ctx, replace_request& request, replace_request::encoded_response_type&& encoded)
70
68
  {
71
- replace_response response{ request.id, encoded.opaque(), ec };
72
- if (ec && response.opaque == 0) {
73
- response.opaque = request.opaque;
74
- }
75
- if (!ec) {
69
+ replace_response response{ ctx };
70
+ if (!response.ctx.ec) {
76
71
  response.cas = encoded.cas();
77
72
  response.token = encoded.body().token();
78
73
  response.token.partition_id = request.partition;
79
- response.token.bucket_name = response.id.bucket;
74
+ response.token.bucket_name = response.ctx.id.bucket;
80
75
  }
81
76
  return response;
82
77
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
20
20
  #include <tao/json.hpp>
21
21
 
22
22
  #include <version.hxx>
23
+ #include <error_context/search.hxx>
23
24
 
24
25
  namespace couchbase::operations
25
26
  {
@@ -87,7 +88,7 @@ struct search_response {
87
88
  std::vector<numeric_range_facet> numeric_ranges{};
88
89
  };
89
90
 
90
- std::error_code ec;
91
+ error_context::search ctx;
91
92
  std::string status{};
92
93
  search_meta_data meta_data{};
93
94
  std::string error{};
@@ -99,6 +100,7 @@ struct search_request {
99
100
  using response_type = search_response;
100
101
  using encoded_request_type = io::http_request;
101
102
  using encoded_response_type = io::http_response;
103
+ using error_context_type = error_context::search;
102
104
 
103
105
  static const inline service_type type = service_type::search;
104
106
 
@@ -127,10 +129,11 @@ struct search_request {
127
129
  std::map<std::string, std::string> facets{};
128
130
 
129
131
  std::map<std::string, tao::json::value> raw{};
132
+ std::string body_str{};
130
133
 
131
134
  [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& context)
132
135
  {
133
- tao::json::value body{
136
+ tao::json::value body = tao::json::value{
134
137
  { "query", query },
135
138
  { "explain", explain },
136
139
  { "ctl", { { "timeout", timeout.count() } } },
@@ -195,7 +198,8 @@ struct search_request {
195
198
  encoded.headers["content-type"] = "application/json";
196
199
  encoded.method = "POST";
197
200
  encoded.path = fmt::format("/api/index/{}/query", index_name);
198
- encoded.body = tao::json::to_string(body);
201
+ body_str = tao::json::to_string(body);
202
+ encoded.body = body_str;
199
203
  if (context.options.show_queries) {
200
204
  spdlog::info("SEARCH: {}", tao::json::to_string(body["query"]));
201
205
  } else {
@@ -206,13 +210,22 @@ struct search_request {
206
210
  };
207
211
 
208
212
  search_response
209
- make_response(std::error_code ec, search_request& request, search_request::encoded_response_type&& encoded)
213
+ make_response(error_context::search&& ctx, search_request& request, search_request::encoded_response_type&& encoded)
210
214
  {
211
- search_response response{ ec };
215
+ search_response response{ ctx };
212
216
  response.meta_data.client_context_id = request.client_context_id;
213
- if (!ec) {
217
+ response.ctx.index_name = request.index_name;
218
+ response.ctx.query = tao::json::to_string(request.query);
219
+ response.ctx.parameters = request.body_str;
220
+ if (!response.ctx.ec) {
214
221
  if (encoded.status_code == 200) {
215
- auto payload = tao::json::from_string(encoded.body);
222
+ tao::json::value payload{};
223
+ try {
224
+ payload = tao::json::from_string(encoded.body);
225
+ } catch (tao::json::pegtl::parse_error& e) {
226
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
227
+ return response;
228
+ }
216
229
  response.meta_data.metrics.took = std::chrono::nanoseconds(payload.at("took").get_unsigned());
217
230
  response.meta_data.metrics.max_score = payload.at("max_score").as<double>();
218
231
  response.meta_data.metrics.total_rows = payload.at("total_hits").get_unsigned();
@@ -232,7 +245,7 @@ make_response(std::error_code ec, search_request& request, search_request::encod
232
245
  }
233
246
  }
234
247
  } else {
235
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
248
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
236
249
  return response;
237
250
  }
238
251
  const auto* rows = payload.find("hits");
@@ -349,21 +362,29 @@ make_response(std::error_code ec, search_request& request, search_request::encod
349
362
  return response;
350
363
  }
351
364
  if (encoded.status_code == 400) {
352
- auto payload = tao::json::from_string(encoded.body);
365
+ tao::json::value payload{};
366
+ try {
367
+ payload = tao::json::from_string(encoded.body);
368
+ } catch (tao::json::pegtl::parse_error& e) {
369
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
370
+ return response;
371
+ }
353
372
  response.status = payload.at("status").get_string();
354
373
  response.error = payload.at("error").get_string();
355
374
  if (response.error.find("index not found") != std::string::npos) {
356
- response.ec = std::make_error_code(error::common_errc::index_not_found);
375
+ response.ctx.ec = std::make_error_code(error::common_errc::index_not_found);
357
376
  return response;
358
- } else if (response.error.find("no planPIndexes for indexName") != std::string::npos) {
359
- response.ec = std::make_error_code(error::search_errc::index_not_ready);
377
+ }
378
+ if (response.error.find("no planPIndexes for indexName") != std::string::npos) {
379
+ response.ctx.ec = std::make_error_code(error::search_errc::index_not_ready);
360
380
  return response;
361
- } else if (response.error.find("pindex_consistency mismatched partition") != std::string::npos) {
362
- response.ec = std::make_error_code(error::search_errc::consistency_mismatch);
381
+ }
382
+ if (response.error.find("pindex_consistency mismatched partition") != std::string::npos) {
383
+ response.ctx.ec = std::make_error_code(error::search_errc::consistency_mismatch);
363
384
  return response;
364
385
  }
365
386
  }
366
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
387
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
367
388
  }
368
389
  return response;
369
390
  }
@@ -25,9 +25,7 @@ namespace couchbase::operations
25
25
  {
26
26
 
27
27
  struct touch_response {
28
- document_id id;
29
- std::uint32_t opaque;
30
- std::error_code ec{};
28
+ error_context::key_value ctx;
31
29
  std::uint64_t cas{};
32
30
  };
33
31
 
@@ -53,13 +51,10 @@ struct touch_request {
53
51
  };
54
52
 
55
53
  touch_response
56
- make_response(std::error_code ec, touch_request& request, touch_request::encoded_response_type&& encoded)
54
+ make_response(error_context::key_value&& ctx, touch_request&, touch_request::encoded_response_type&& encoded)
57
55
  {
58
- touch_response response{ request.id, encoded.opaque(), ec };
59
- if (ec && response.opaque == 0) {
60
- response.opaque = request.opaque;
61
- }
62
- if (!ec) {
56
+ touch_response response{ ctx };
57
+ if (!response.ctx.ec) {
63
58
  response.cas = encoded.cas();
64
59
  }
65
60
  return response;
@@ -25,9 +25,7 @@ namespace couchbase::operations
25
25
  {
26
26
 
27
27
  struct unlock_response {
28
- document_id id;
29
- std::uint32_t opaque;
30
- std::error_code ec{};
28
+ error_context::key_value ctx;
31
29
  std::uint64_t cas{};
32
30
  };
33
31
 
@@ -53,13 +51,10 @@ struct unlock_request {
53
51
  };
54
52
 
55
53
  unlock_response
56
- make_response(std::error_code ec, unlock_request& request, unlock_request::encoded_response_type&& encoded)
54
+ make_response(error_context::key_value&& ctx, unlock_request&, unlock_request::encoded_response_type&& encoded)
57
55
  {
58
- unlock_response response{ request.id, encoded.opaque(), ec };
59
- if (ec && response.opaque == 0) {
60
- response.opaque = request.opaque;
61
- }
62
- if (!ec) {
56
+ unlock_response response{ ctx };
57
+ if (!response.ctx.ec) {
63
58
  response.cas = encoded.cas();
64
59
  }
65
60
  return response;
@@ -26,9 +26,7 @@ namespace couchbase::operations
26
26
  {
27
27
 
28
28
  struct upsert_response {
29
- document_id id;
30
- std::uint32_t opaque;
31
- std::error_code ec{};
29
+ error_context::key_value ctx;
32
30
  std::uint64_t cas{};
33
31
  mutation_token token{};
34
32
  };
@@ -64,17 +62,14 @@ struct upsert_request {
64
62
  };
65
63
 
66
64
  upsert_response
67
- make_response(std::error_code ec, upsert_request& request, upsert_request::encoded_response_type&& encoded)
65
+ make_response(error_context::key_value&& ctx, upsert_request& request, upsert_request::encoded_response_type&& encoded)
68
66
  {
69
- upsert_response response{ request.id, encoded.opaque(), ec };
70
- if (ec && response.opaque == 0) {
71
- response.opaque = request.opaque;
72
- }
73
- if (!ec) {
67
+ upsert_response response{ ctx };
68
+ if (!response.ctx.ec) {
74
69
  response.cas = encoded.cas();
75
70
  response.token = encoded.body().token();
76
71
  response.token.partition_id = request.partition;
77
- response.token.bucket_name = response.id.bucket;
72
+ response.token.bucket_name = response.ctx.id.bucket;
78
73
  }
79
74
  return response;
80
75
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
20
20
  #include <tao/json.hpp>
21
21
  #include <operations/design_document.hxx>
22
22
  #include <utils/url_codec.hxx>
23
+ #include <error_context/view.hxx>
23
24
 
24
25
  namespace couchbase::operations
25
26
  {
@@ -40,8 +41,7 @@ struct document_view_response {
40
41
  std::string message;
41
42
  };
42
43
 
43
- std::string client_context_id;
44
- std::error_code ec;
44
+ error_context::view ctx;
45
45
  document_view_response::meta_data meta_data{};
46
46
  std::vector<document_view_response::row> rows{};
47
47
  std::optional<problem> error{};
@@ -51,6 +51,7 @@ struct document_view_request {
51
51
  using response_type = document_view_response;
52
52
  using encoded_request_type = io::http_request;
53
53
  using encoded_response_type = io::http_response;
54
+ using error_context_type = error_context::view;
54
55
 
55
56
  static const inline service_type type = service_type::views;
56
57
 
@@ -88,11 +89,10 @@ struct document_view_request {
88
89
 
89
90
  enum class sort_order { ascending, descending };
90
91
  std::optional<sort_order> order;
92
+ std::vector<std::string> query_string{};
91
93
 
92
94
  [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
93
95
  {
94
- std::vector<std::string> query_string;
95
-
96
96
  if (debug) {
97
97
  query_string.emplace_back("debug=true");
98
98
  }
@@ -177,12 +177,22 @@ struct document_view_request {
177
177
  };
178
178
 
179
179
  document_view_response
180
- make_response(std::error_code ec, document_view_request& request, document_view_request::encoded_response_type&& encoded)
180
+ make_response(error_context::view&& ctx, document_view_request& request, document_view_request::encoded_response_type&& encoded)
181
181
  {
182
- document_view_response response{ request.client_context_id, ec };
183
- if (!ec) {
182
+ document_view_response response{ ctx };
183
+ response.ctx.client_context_id = request.client_context_id;
184
+ response.ctx.design_document_name = request.document_name;
185
+ response.ctx.view_name = request.view_name;
186
+ response.ctx.query_string = request.query_string;
187
+ if (!response.ctx.ec) {
184
188
  if (encoded.status_code == 200) {
185
- tao::json::value payload = tao::json::from_string(encoded.body);
189
+ tao::json::value payload{};
190
+ try {
191
+ payload = tao::json::from_string(encoded.body);
192
+ } catch (tao::json::pegtl::parse_error& e) {
193
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
194
+ return response;
195
+ }
186
196
  const auto* total_rows = payload.find("total_rows");
187
197
  if (total_rows != nullptr && total_rows->is_unsigned()) {
188
198
  response.meta_data.total_rows = total_rows->get_unsigned();
@@ -205,7 +215,13 @@ make_response(std::error_code ec, document_view_request& request, document_view_
205
215
  }
206
216
  }
207
217
  } else if (encoded.status_code == 400) {
208
- tao::json::value payload = tao::json::from_string(encoded.body);
218
+ tao::json::value payload{};
219
+ try {
220
+ payload = tao::json::from_string(encoded.body);
221
+ } catch (tao::json::pegtl::parse_error& e) {
222
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
223
+ return response;
224
+ }
209
225
  document_view_response::problem problem{};
210
226
  const auto* error = payload.find("error");
211
227
  if (error != nullptr && error->is_string()) {
@@ -216,11 +232,11 @@ make_response(std::error_code ec, document_view_request& request, document_view_
216
232
  problem.message = reason->get_string();
217
233
  }
218
234
  response.error.emplace(problem);
219
- response.ec = std::make_error_code(error::common_errc::invalid_argument);
235
+ response.ctx.ec = std::make_error_code(error::common_errc::invalid_argument);
220
236
  } else if (encoded.status_code == 404) {
221
- response.ec = std::make_error_code(error::view_errc::design_document_not_found);
237
+ response.ctx.ec = std::make_error_code(error::view_errc::design_document_not_found);
222
238
  } else {
223
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
239
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
224
240
  }
225
241
  }
226
242
  return response;
@@ -27,14 +27,14 @@ namespace couchbase::operations
27
27
  {
28
28
 
29
29
  struct group_drop_response {
30
- std::string client_context_id;
31
- std::error_code ec;
30
+ error_context::http ctx;
32
31
  };
33
32
 
34
33
  struct group_drop_request {
35
34
  using response_type = group_drop_response;
36
35
  using encoded_request_type = io::http_request;
37
36
  using encoded_response_type = io::http_response;
37
+ using error_context_type = error_context::http;
38
38
 
39
39
  static const inline service_type type = service_type::management;
40
40
 
@@ -51,18 +51,18 @@ struct group_drop_request {
51
51
  };
52
52
 
53
53
  group_drop_response
54
- make_response(std::error_code ec, group_drop_request& request, group_drop_request::encoded_response_type&& encoded)
54
+ make_response(error_context::http&& ctx, group_drop_request&, group_drop_request::encoded_response_type&& encoded)
55
55
  {
56
- group_drop_response response{ request.client_context_id, ec };
57
- if (!ec) {
56
+ group_drop_response response{ ctx };
57
+ if (!response.ctx.ec) {
58
58
  switch (encoded.status_code) {
59
59
  case 200:
60
60
  break;
61
61
  case 404:
62
- response.ec = std::make_error_code(error::management_errc::group_not_found);
62
+ response.ctx.ec = std::make_error_code(error::management_errc::group_not_found);
63
63
  break;
64
64
  default:
65
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
65
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
66
66
  break;
67
67
  }
68
68
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -27,8 +27,7 @@ namespace couchbase::operations
27
27
  {
28
28
 
29
29
  struct group_get_response {
30
- std::string client_context_id;
31
- std::error_code ec;
30
+ error_context::http ctx;
32
31
  rbac::group group{};
33
32
  };
34
33
 
@@ -36,6 +35,7 @@ struct group_get_request {
36
35
  using response_type = group_get_response;
37
36
  using encoded_request_type = io::http_request;
38
37
  using encoded_response_type = io::http_response;
38
+ using error_context_type = error_context::http;
39
39
 
40
40
  static const inline service_type type = service_type::management;
41
41
 
@@ -53,20 +53,24 @@ struct group_get_request {
53
53
  };
54
54
 
55
55
  group_get_response
56
- make_response(std::error_code ec, group_get_request& request, group_get_request::encoded_response_type&& encoded)
56
+ make_response(error_context::http&& ctx, group_get_request&, group_get_request::encoded_response_type&& encoded)
57
57
  {
58
- group_get_response response{ request.client_context_id, ec };
59
- if (!ec) {
58
+ group_get_response response{ ctx };
59
+ if (!response.ctx.ec) {
60
60
  switch (encoded.status_code) {
61
61
  case 200: {
62
- tao::json::value payload = tao::json::from_string(encoded.body);
63
- response.group = payload.as<rbac::group>();
62
+ try {
63
+ response.group = tao::json::from_string(encoded.body).as<rbac::group>();
64
+ } catch (tao::json::pegtl::parse_error& e) {
65
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
66
+ return response;
67
+ }
64
68
  } break;
65
69
  case 404:
66
- response.ec = std::make_error_code(error::management_errc::group_not_found);
70
+ response.ctx.ec = std::make_error_code(error::management_errc::group_not_found);
67
71
  break;
68
72
  default:
69
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
73
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
70
74
  break;
71
75
  }
72
76
  }