Skip to content

Commit 7cfb32d

Browse files
Put a clearer error string in GraphQL error. (#4500)
## Motivation The GraphQL error messages can be quite obscure. Here we attempt to clarify what is going on Fixes #4459 ## Proposal The cryptic error message indicates the following: * The "location" indicate in a cryptic way that the claim was problematic. * The "Request processing was cancelled" is due to the grouping of issues in the faucet. Let us make all queries fail for the same reason. * The array indicates the operation being used. Maybe it could be left. So, the change is to keep the message and make it clear. After those changes, the error message is now ```GraphQL ERROR linera: Error is GraphQL error: [String("Signer doesn't have key to sign for chain 03bea8b215a1c415ad4affec891fa62ef2bd39cb4f9b774dda86cdc0b05583fd")] ``` which is much clearer. ## Test Plan The CI. No attempt has been made to add a test. The original error was that the `LINERA_KEYSTORE` was not set. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None.
1 parent d26fde6 commit 7cfb32d

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

linera-faucet/client/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,25 @@ impl Faucet {
7373
.await?;
7474

7575
if let Some(errors) = response.errors {
76-
Err(ErrorInner::GraphQl(errors).into())
76+
// Extract just the error messages, ignore locations and path
77+
let messages = errors
78+
.iter()
79+
.filter_map(|error| {
80+
error
81+
.get("message")
82+
.and_then(|msg| msg.as_str())
83+
.map(|s| s.to_string())
84+
})
85+
.collect::<Vec<_>>();
86+
87+
if messages.is_empty() {
88+
Err(ErrorInner::GraphQl(errors).into())
89+
} else {
90+
Err(
91+
ErrorInner::GraphQl(vec![serde_json::Value::String(messages.join("; "))])
92+
.into(),
93+
)
94+
}
7795
} else {
7896
Ok(response
7997
.data
@@ -111,7 +129,6 @@ impl Faucet {
111129
struct Response {
112130
claim: ChainDescription,
113131
}
114-
115132
Ok(self
116133
.query::<Response>(format!("mutation {{ claim(owner: \"{owner}\") }}"))
117134
.await?

linera-faucet/server/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,26 @@ where
435435
return Ok(()); // Don't return an error, so we retry.
436436
}
437437
chain_err => {
438+
for request in valid_requests {
439+
let _ = request
440+
.responder
441+
.send(Err(Error::new(chain_err.to_string())));
442+
}
438443
return Err(
439444
ChainClientError::LocalNodeError(LocalNodeError::WorkerError(
440445
WorkerError::ChainError(chain_err.into()),
441446
))
442447
.into(),
443-
)
448+
);
444449
}
445450
}
446451
}
447-
Err(err) => return Err(err.into()),
452+
Err(err) => {
453+
for request in valid_requests {
454+
let _ = request.responder.send(Err(Error::new(err.to_string())));
455+
}
456+
return Err(err.into());
457+
}
448458
Ok(ClientOutcome::Committed(certificate)) => certificate,
449459
Ok(ClientOutcome::WaitForTimeout(timeout)) => {
450460
let error_msg = format!(

0 commit comments

Comments
 (0)