Skip to content

Commit 453ba63

Browse files
committed
CXX-785 Clean up some latent TODO items, mostly around exceptions
1 parent 4553093 commit 453ba63

File tree

13 files changed

+30
-26
lines changed

13 files changed

+30
-26
lines changed

src/bsoncxx/builder/core.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ class BSONCXX_API core {
4444
public:
4545
class BSONCXX_PRIVATE impl;
4646

47-
// TODO this should fit with the larger bson exception heirarchy
48-
class invalid_state : public std::runtime_error {};
49-
5047
///
5148
/// Constructs an empty BSON datum.
5249
///

src/bsoncxx/document/element.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class BSONCXX_API element {
8282

8383
stdx::string_view key() const;
8484

85-
// TODO figure out a better exception than std::runtime_error
8685
types::b_double get_double() const;
8786
types::b_utf8 get_utf8() const;
8887
types::b_document get_document() const;

src/mongocxx/bulk_write.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void bulk_write::append(const model::write& operation) {
8383
break;
8484
}
8585
case write_type::k_uninitialized:
86-
break; // TODO: something exceptiony
86+
break; // TODO: something exceptiony (see CXX-630)
8787
}
8888
}
8989

src/mongocxx/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ client::client(const class uri& uri, const options::client& options)
4242
auto mongoc_opts = options::make_ssl_opts(*options.ssl_opts());
4343
libmongoc::client_set_ssl_opts(_get_impl().client_t, &mongoc_opts);
4444
#else
45-
// TODO: For now, just ignoring. Should we throw?
45+
throw exception{make_error_code(error_code::k_ssl_not_supported)};
4646
#endif
4747
}
4848
}

src/mongocxx/client.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN
4747
/// mongocxx::client mongo_client("mongodb://localhost:27017");
4848
/// @endcode
4949
///
50-
/// @todo Make iterable for databases on the server
51-
/// @todo Add + implement missing client api methods
52-
///
5350
class MONGOCXX_API client {
5451

5552
public:

src/mongocxx/database.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ class client;
3838
/// Acts as a gateway for accessing collections that are contained within a database. It inherits
3939
/// all of its default settings from the client that creates it.
4040
///
41-
/// @todo Make iterable for collections in the database
4241
/// @todo Add auth functions (add_user, remove_all_users, remove_user)
43-
42+
///
4443
class MONGOCXX_API database {
4544
public:
4645
///

src/mongocxx/exception/error_code.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ enum class error_code : std::int32_t {
2626
k_invalid_collection_object,
2727
k_invalid_database_object,
2828
k_invalid_parameter,
29+
k_ssl_not_supported,
30+
k_unknown_read_concern,
31+
k_unknown_write_concern,
2932
};
3033

3134
MONGOCXX_INLINE_NAMESPACE_END

src/mongocxx/exception/private/error_category.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ class mongocxx_error_category_impl final : public std::error_category {
393393
return "invalid use of default constructed or moved-from mongocxx::database object";
394394
case error_code::k_invalid_parameter:
395395
return "an invalid or out-of-bounds parameter was provided";
396+
case error_code::k_ssl_not_supported:
397+
return "SSL support not available";
398+
case error_code::k_unknown_read_concern:
399+
return "invalid attempt to set an unknown read concern level";
400+
case error_code::k_unknown_write_concern:
401+
return "invalid attempt to set an unknown write concern level";
396402
default:
397403
return "unknown mongocxx error";
398404
}

src/mongocxx/instance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ log_level convert_log_level(::mongoc_log_level_t mongoc_log_level) {
4343
case MONGOC_LOG_LEVEL_TRACE:
4444
return log_level::k_trace;
4545
default:
46-
// TODO: MONGOCXX_UNREACHABLE (CXX-628)
47-
std::abort();
46+
MONGOCXX_UNREACHABLE;
4847
}
4948
}
5049

src/mongocxx/pool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
#include <mongocxx/config/prelude.hpp>
2222

2323
#include <mongocxx/client.hpp>
24+
#include <mongocxx/exception/error_code.hpp>
25+
#include <mongocxx/exception/exception.hpp>
26+
#include <mongocxx/exception/private/error_code.hpp>
2427
#include <mongocxx/private/client.hpp>
2528
#include <mongocxx/private/pool.hpp>
26-
#include <mongocxx/private/uri.hpp>
2729
#include <mongocxx/private/ssl.hpp>
30+
#include <mongocxx/private/uri.hpp>
2831

2932
namespace mongocxx {
3033
MONGOCXX_INLINE_NAMESPACE_BEGIN
@@ -49,7 +52,7 @@ pool::pool(const uri& mongodb_uri, stdx::optional<options::ssl> ssl_options)
4952
// temporary as the driver will copy it.
5053
libmongoc::client_pool_set_ssl_opts(_impl->client_pool_t, &mongoc_opts);
5154
#else
52-
// TODO: For now, just ignoring. Should we throw?
55+
throw exception{make_error_code(error_code::k_ssl_not_supported)};
5356
#endif
5457
}
5558
}

src/mongocxx/read_concern.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
// limitations under the License.
1414

1515
#include <mongocxx/read_concern.hpp>
16+
1617
#include <mongocxx/private/read_concern.hpp>
1718

1819
#include <bsoncxx/stdx/make_unique.hpp>
20+
#include <mongocxx/exception/error_code.hpp>
21+
#include <mongocxx/exception/exception.hpp>
22+
#include <mongocxx/exception/private/error_code.hpp>
1923
#include <mongocxx/private/libmongoc.hpp>
2024

2125
namespace mongocxx {
@@ -53,9 +57,7 @@ void read_concern::acknowledge_level(read_concern::level rc_level) {
5357
MONGOC_READ_CONCERN_LEVEL_MAJORITY);
5458
break;
5559
default:
56-
// TODO throw a mongocxx exception
57-
throw std::invalid_argument(
58-
"acknowledge_level can only be used to set levels of k_local or k_majority.");
60+
throw exception{make_error_code(error_code::k_unknown_read_concern)};
5961
}
6062
}
6163

src/mongocxx/test/write_concern.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "catch.hpp"
1616

17+
#include <mongocxx/exception/exception.hpp>
1718
#include <mongocxx/write_concern.hpp>
1819

1920
using namespace mongocxx;
@@ -91,9 +92,8 @@ TEST_CASE("write_concern fields may be set and retrieved", "[write_concern]") {
9192
}
9293

9394
SECTION("setting invalid acknowledge levels throws") {
94-
// TODO fix exception
95-
REQUIRE_THROWS_AS(wc.acknowledge_level(write_concern::level::k_unknown), std::invalid_argument);
96-
REQUIRE_THROWS_AS(wc.acknowledge_level(write_concern::level::k_tag), std::invalid_argument);
95+
REQUIRE_THROWS_AS(wc.acknowledge_level(write_concern::level::k_unknown), exception);
96+
REQUIRE_THROWS_AS(wc.acknowledge_level(write_concern::level::k_tag), exception);
9797
wc.tag("AnyTag");
9898
REQUIRE_NOTHROW(wc.acknowledge_level(write_concern::level::k_tag));
9999
}

src/mongocxx/write_concern.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
#include <bsoncxx/stdx/make_unique.hpp>
2020
#include <bsoncxx/stdx/optional.hpp>
21+
#include <mongocxx/exception/error_code.hpp>
22+
#include <mongocxx/exception/exception.hpp>
2123
#include <mongocxx/exception/logic_error.hpp>
2224
#include <mongocxx/exception/private/error_category.hpp>
2325
#include <mongocxx/exception/private/error_code.hpp>
2426
#include <mongocxx/private/libmongoc.hpp>
2527
#include <mongocxx/private/write_concern.hpp>
2628
#include <mongocxx/stdx.hpp>
29+
#include <mongocxx/stdx.hpp>
2730

2831
namespace mongocxx {
2932
MONGOCXX_INLINE_NAMESPACE_BEGIN
@@ -85,11 +88,7 @@ void write_concern::acknowledge_level(write_concern::level confirm_level) {
8588
if (libmongoc::write_concern_get_w(_impl->write_concern_t) == MONGOC_WRITE_CONCERN_W_TAG)
8689
return;
8790
default:
88-
// TODO throw a mongocxx exception
89-
throw std::invalid_argument(
90-
"acknowledge_level can only be used to set levels of k_default, k_majority, or "
91-
"k_unacknowledged.");
92-
return;
91+
throw exception{make_error_code(error_code::k_unknown_write_concern)};
9392
}
9493
libmongoc::write_concern_set_w(_impl->write_concern_t, w);
9594
}

0 commit comments

Comments
 (0)