Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: changed some str to Strings for better errors #290

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion costs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ repository = "https://github.com/dashpay/grovedb"


[dependencies]
thiserror = "1.0.58"
thiserror = "1.0.59"
intmap = "2.0.0"
integer-encoding = "4.0.0"
2 changes: 1 addition & 1 deletion grovedb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation = "https://docs.rs/grovedb"

[dependencies]
grovedb-merk = { version = "1.0.0-rc.2", path = "../merk", optional = true, default-features = false }
thiserror = { version = "1.0.58", optional = true }
thiserror = { version = "1.0.59", optional = true }
tempfile = { version = "3.10.1", optional = true }
bincode = { version = "2.0.0-rc.3" }
grovedb-storage = { version = "1.0.0-rc.2", path = "../storage", optional = true }
Expand Down
36 changes: 4 additions & 32 deletions grovedb/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
// MIT LICENSE
//
// Copyright (c) 2021 Dash Core Group
//
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the
// Software without restriction, including without
// limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! GroveDB Errors

/// GroveDB Errors
Expand Down Expand Up @@ -139,15 +111,15 @@ pub enum Error {
// Client allowed errors
#[error("just in time element flags client error: {0}")]
/// Just in time element flags client error
JustInTimeElementFlagsClientError(&'static str),
JustInTimeElementFlagsClientError(String),

#[error("split removal bytes client error: {0}")]
/// Split removal bytes client error
SplitRemovalBytesClientError(&'static str),
SplitRemovalBytesClientError(String),

#[error("client returned non client error: {0}")]
/// Client returned non client error
ClientReturnedNonClientError(&'static str),
ClientReturnedNonClientError(String),

#[error("override not allowed error: {0}")]
/// Override not allowed
Expand All @@ -160,7 +132,7 @@ pub enum Error {
// Support errors
#[error("not supported: {0}")]
/// Not supported
NotSupported(&'static str),
NotSupported(String),

// Merk errors
#[error("merk error: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/operations/delete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl GroveDb {
)))
} else {
Err(Error::NotSupported(
"deletion operation for non empty tree not currently supported",
"deletion operation for non empty tree not currently supported".to_string(),
))
};
result.wrap_with_cost(cost)
Expand Down
10 changes: 5 additions & 5 deletions grovedb/src/operations/get/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ where {
) -> CostResult<Vec<u8>, Error> {
if transaction.is_some() {
Err(Error::NotSupported(
"transactions are not currently supported",
"transactions are not currently supported".to_string(),
))
.wrap_with_cost(Default::default())
} else if is_verbose {
Expand Down Expand Up @@ -404,11 +404,11 @@ where {
transaction: TransactionArg,
) -> CostResult<Vec<PathKeyOptionalElementTrio>, Error> {
let max_results = cost_return_on_error_default!(path_query.query.limit.ok_or(
Error::NotSupported("limits must be set in query_keys_optional",)
Error::NotSupported("limits must be set in query_keys_optional".to_string())
)) as usize;
if path_query.query.offset.is_some() {
return Err(Error::NotSupported(
"offsets are not supported in query_raw_keys_optional",
"offsets are not supported in query_raw_keys_optional".to_string(),
))
.wrap_with_cost(OperationCost::default());
}
Expand Down Expand Up @@ -449,11 +449,11 @@ where {
transaction: TransactionArg,
) -> CostResult<Vec<PathKeyOptionalElementTrio>, Error> {
let max_results = cost_return_on_error_default!(path_query.query.limit.ok_or(
Error::NotSupported("limits must be set in query_raw_keys_optional",)
Error::NotSupported("limits must be set in query_raw_keys_optional".to_string())
)) as usize;
if path_query.query.offset.is_some() {
return Err(Error::NotSupported(
"offsets are not supported in query_raw_keys_optional",
"offsets are not supported in query_raw_keys_optional".to_string(),
))
.wrap_with_cost(OperationCost::default());
}
Expand Down
4 changes: 2 additions & 2 deletions grovedb/src/operations/proof/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ impl GroveDb {
{
// must have a limit
let max_results = query.query.limit.ok_or(Error::NotSupported(
"limits must be set in verify_query_with_absence_proof",
"limits must be set in verify_query_with_absence_proof".to_string(),
))? as usize;

// must have no offset
if query.query.offset.is_some() {
return Err(Error::NotSupported(
"offsets are not supported for verify_query_with_absence_proof",
"offsets are not supported for verify_query_with_absence_proof".to_string(),
));
}

Expand Down
5 changes: 3 additions & 2 deletions grovedb/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ impl PathQuery {
path_queries.into_iter().try_for_each(|path_query| {
if path_query.query.offset.is_some() {
return Err(Error::NotSupported(
"can not merge pathqueries with offsets",
"can not merge pathqueries with offsets".to_string(),
));
}
if path_query.query.limit.is_some() {
return Err(Error::NotSupported(
"can not merge pathqueries with limits, consider setting the limit after the \
merge",
merge"
.to_string(),
));
}
path_query
Expand Down
2 changes: 1 addition & 1 deletion merk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub enum Error {

/// Not supported error
#[error("not supported error {0}")]
NotSupported(&'static str),
NotSupported(String),

/// Request amount exceeded error
#[error("request amount exceeded error {0}")]
Expand Down
5 changes: 3 additions & 2 deletions merk/src/proofs/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ impl Query {
// unbounded ranges can not be supported
if conditional_query_item.is_unbounded_range() {
return Err(Error::NotSupported(
"terminal keys are not supported with conditional unbounded ranges",
"terminal keys are not supported with conditional unbounded ranges"
.to_string(),
));
}
let conditional_keys = conditional_query_item.keys()?;
Expand Down Expand Up @@ -237,7 +238,7 @@ impl Query {
for item in self.items.iter() {
if item.is_unbounded_range() {
return Err(Error::NotSupported(
"terminal keys are not supported with unbounded ranges",
"terminal keys are not supported with unbounded ranges".to_string(),
));
}
let keys = item.keys()?;
Expand Down
2 changes: 1 addition & 1 deletion storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ integer-encoding = { version = "4.0.0", optional = true }
grovedb-visualize = { version = "1.0.0-rc.2", path = "../visualize" }
strum = { version = "0.26.2", features = ["derive"] }
grovedb-costs = { version = "1.0.0-rc.2", path = "../costs" }
thiserror = "1.0.37"
thiserror = "1.0.59"
rocksdb = { version = "0.22.0", optional = true }
hex = "0.4.3"
grovedb-path = { version = "1.0.0-rc.2", path = "../path" }
Expand Down
Loading