Skip to content

Commit 4136e40

Browse files
committed
RSCBC-83: Improve error messages for account lock/unlock
1 parent 23adda9 commit 4136e40

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

sdk/couchbase-core/src/memdx/error.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,15 @@ impl Display for ServerError {
322322

323323
if let Some(context) = &self.context {
324324
if let Some(parsed) = Self::parse_context(context) {
325-
base_msg = format!("{}, (context: {})", base_msg, parsed.text);
325+
base_msg.push_str(" (");
326+
if let Some(text) = &parsed.text {
327+
base_msg.push_str(&format!("context: {}, ", text));
328+
}
329+
330+
if let Some(error_ref) = &parsed.error_ref {
331+
base_msg.push_str(&format!("error_ref: {}", error_ref));
332+
}
333+
base_msg.push(')');
326334
}
327335
}
328336

@@ -388,9 +396,9 @@ impl ServerError {
388396
}
389397
};
390398

391-
let text = context_json.error.context.unwrap_or_default();
399+
let text = context_json.error.context;
392400

393-
let error_ref = context_json.error_ref;
401+
let error_ref = context_json.error.error_ref;
394402

395403
let manifest_rev = context_json
396404
.manifest_rev
@@ -407,7 +415,7 @@ impl ServerError {
407415
#[derive(Clone, Debug, PartialEq, Eq)]
408416
#[non_exhaustive]
409417
pub struct ServerErrorContext {
410-
pub text: String,
418+
pub text: Option<String>,
411419
pub error_ref: Option<String>,
412420
pub manifest_rev: Option<u64>,
413421
}
@@ -692,14 +700,14 @@ impl From<io::Error> for Error {
692700
struct ServerErrorContextJsonContext {
693701
#[serde(alias = "context")]
694702
context: Option<String>,
703+
#[serde(alias = "ref")]
704+
pub error_ref: Option<String>,
695705
}
696706

697707
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
698708
struct ServerErrorContextJson {
699709
#[serde(alias = "error", default)]
700710
error: ServerErrorContextJsonContext,
701-
#[serde(alias = "ref")]
702-
pub error_ref: Option<String>,
703711
#[serde(alias = "manifest_uid")]
704712
pub manifest_rev: Option<String>,
705713
}

sdk/couchbase-core/tests/query.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ fn test_query_basic() {
5050
assert_eq!(0, meta.metrics.error_count);
5151
assert_eq!(0, meta.metrics.warning_count);
5252

53-
dbg!(&meta.signature);
54-
5553
assert_eq!(
5654
"{\"$1\":\"boolean\"}",
5755
meta.signature.as_ref().unwrap().get()

sdk/couchbase/src/error.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ impl Error {
8484

8585
if let Some(xerror) = e.context() {
8686
if let Some(parsed) = ServerError::parse_context(xerror) {
87-
extended_context = extended_context.with_xcontent(parsed.text);
87+
if let Some(text) = parsed.text {
88+
extended_context = extended_context.with_xcontent(text);
89+
}
90+
8891
if let Some(error_ref) = parsed.error_ref {
8992
extended_context = extended_context.with_xref(error_ref);
9093
}
9194
}
9295
}
9396

94-
// TODO: error name and desc.
95-
9697
(e.kind().into(), extended_context)
9798
}
9899

0 commit comments

Comments
 (0)