Skip to content

Commit a38d074

Browse files
authored
Merge pull request #3839 from reubenmiller/feat-flows-payload-missing-check
feat: improve error messages when parsing the output messages from a flow
2 parents 05dafb6 + 990b77a commit a38d074

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/extensions/tedge_flows/src/js_value.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,18 @@ impl TryFrom<BTreeMap<String, JsonValue>> for Message {
118118

119119
fn try_from(value: BTreeMap<String, JsonValue>) -> Result<Self, Self::Error> {
120120
let Some(JsonValue::String(topic)) = value.get("topic") else {
121-
return Err(anyhow::anyhow!("Missing message topic").into());
121+
return Err(anyhow::anyhow!("Message is missing the 'topic' property").into());
122122
};
123123
let payload = match value.get("payload") {
124124
Some(JsonValue::String(payload)) => payload.to_owned().into_bytes(),
125125
Some(JsonValue::Bytes(payload)) => payload.to_owned(),
126-
_ => return Err(anyhow::anyhow!("Missing message payload").into()),
126+
None => return Err(anyhow::anyhow!("Message is missing the 'payload' property").into()),
127+
_ => {
128+
return Err(anyhow::anyhow!(
129+
"Unexpected payload format. Expected either a string or an ArrayBuffer"
130+
)
131+
.into())
132+
}
127133
};
128134
let timestamp = value
129135
.get("timestamp")

0 commit comments

Comments
 (0)