Skip to content

Commit

Permalink
Merge pull request #2586 from Ruadhri17/mqtt-large-failure-reason
Browse files Browse the repository at this point in the history
Limit the length of the message for failed operation
  • Loading branch information
reubenmiller authored Jan 16, 2024
2 parents 2cf1aaf + b0e8508 commit 5eb1219
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/core/c8y_api/src/smartrest/smartrest_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde::ser::SerializeSeq;
use serde::Deserialize;
use serde::Serialize;
use serde::Serializer;
use tracing::warn;

pub type SmartRest = String;

Expand All @@ -21,7 +22,13 @@ pub fn set_operation_executing(operation: impl C8yOperation) -> String {

/// Generates a SmartREST message to set the provided operation to failed with the provided reason
pub fn fail_operation(operation: impl C8yOperation, reason: &str) -> String {
fields_to_csv_string(&["502", operation.name(), reason])
// If the failure reason exceeds 500 bytes, trancuate it
if reason.len() <= 500 {
fields_to_csv_string(&["502", operation.name(), reason])
} else {
warn!("Failure reason too long, message trancuated to 500 bytes");
fields_to_csv_string(&["502", operation.name(), &reason[..500]])
}
}

/// Generates a SmartREST message to set the provided operation to successful without a payload
Expand Down

1 comment on commit 5eb1219

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
380 0 3 380 100 54m22.111999999s

Please sign in to comment.