Skip to content

Commit b9faaf3

Browse files
authored
fix(message): prevent panic on malformed UUID in log fields (#1562)
### **SUMMARY** Fixes a daemon crash caused by `.unwrap()` when parsing UUIDs from log fields. Invalid UUIDs from node logs would panic the system. Changes are in `libraries/message/src/common.rs` inside `LogMessage::from(...)`. --- ### FIX #### **Before** ```rust id="9et2c1" .map(|id| BuildId(Uuid::parse_str(&id).unwrap())) ``` #### **After** ```rust id="x68dih" .and_then(|id| Uuid::parse_str(&id).ok().map(BuildId)) ``` --- ### **VERIFICATION** To verify, emit a log from a node process with an invalid UUID such as `{"fields": {"build_id": "not-a-uuid"}}`. Before this change, the daemon would panic while converting the log message. After the fix, the daemon continues running normally and simply treats the invalid UUID field as `None`.
2 parents 33066b9 + 4c4fafc commit b9faaf3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

libraries/message/src/common.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ impl From<LogMessageHelper> for LogMessage {
5050
LogMessage {
5151
build_id: helper.build_id.or(fields
5252
.and_then(|f| f.get("build_id").cloned())
53-
.map(|id| BuildId(Uuid::parse_str(&id).unwrap()))),
53+
.and_then(|id| Uuid::parse_str(&id).ok().map(BuildId))),
5454
dataflow_id: helper.dataflow_id.or(fields
5555
.and_then(|f| f.get("dataflow_id").cloned())
56-
.map(|id| DataflowId::from(Uuid::parse_str(&id).unwrap()))),
56+
.and_then(|id| Uuid::parse_str(&id).ok().map(DataflowId::from))),
5757
node_id: helper.node_id.or(fields
5858
.and_then(|f| f.get("node_id").cloned())
5959
.map(|id| NodeId(id))),
60-
daemon_id: helper
61-
.daemon_id
62-
.or(fields.and_then(|f| f.get("daemon_id").cloned()).map(|id| {
60+
daemon_id: helper.daemon_id.or(fields
61+
.and_then(|f| f.get("daemon_id").cloned())
62+
.and_then(|id| {
6363
let parts: Vec<&str> = id.splitn(2, '-').collect();
6464
if parts.len() == 2 {
65-
DaemonId {
65+
Uuid::parse_str(parts[1]).ok().map(|uuid| DaemonId {
6666
machine_id: Some(parts[0].to_string()),
67-
uuid: Uuid::parse_str(parts[1]).unwrap(),
68-
}
67+
uuid,
68+
})
6969
} else {
70-
DaemonId {
70+
Uuid::parse_str(&parts[0]).ok().map(|uuid| DaemonId {
7171
machine_id: None,
72-
uuid: Uuid::parse_str(&parts[0]).unwrap(),
73-
}
72+
uuid,
73+
})
7474
}
7575
})),
7676
level: helper.level,

0 commit comments

Comments
 (0)