Skip to content

feat: Attach topic to c8y message conversion error#3217

Merged
Bravo555 merged 1 commit intothin-edge:mainfrom
Bravo555:improve/c8y-converter-error-reporting
Oct 31, 2024
Merged

feat: Attach topic to c8y message conversion error#3217
Bravo555 merged 1 commit intothin-edge:mainfrom
Bravo555:improve/c8y-converter-error-reporting

Conversation

@Bravo555
Copy link
Copy Markdown
Member

Proposed changes

Improve error reporting in c8y mapper by printing the topic when there was an error converting a message on that topic.

Example: when publishing an invalid command metadata message: $ tedge mqtt pub -r te/device/main///cmd/config_snapshot 'a'

before:
ERROR: Mapping error: expected value at line 1 column 1

after:
ERROR: Mapping error: Failed to convert a message on topic 'te/device/main///cmd/config_snapshot': expected value at line 1 column 1

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@Bravo555 Bravo555 added improvement User value theme:troubleshooting Theme: Troubleshooting and remote control labels Oct 30, 2024
@Bravo555 Bravo555 temporarily deployed to Test Pull Request October 30, 2024 14:31 — with GitHub Actions Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 30, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
526 0 2 526 100 1h37m28.907042999s

@Bravo555 Bravo555 force-pushed the improve/c8y-converter-error-reporting branch from 86261fc to 6d04337 Compare October 30, 2024 22:35
@Bravo555 Bravo555 temporarily deployed to Test Pull Request October 30, 2024 22:35 — with GitHub Actions Inactive
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/extensions/c8y_mapper_ext/src/converter.rs 91.30% 0 Missing and 2 partials ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

Comment on lines +145 to +148
let error = MessageConversionError {
error,
topic: input.topic.name.clone(),
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about moving this MessageConversionError creation logic into the convert function and propagate the same type into wrap_errors and new_error_message functions as well, since the new_error_message function already has the logic below that creates the message on the error topic. That

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

wrap_errors is also used in other places where we don't have a message we're converting, for example auto entity registration. Then using the topic of a message that causes auto-registration (for example some measurement) next to any errors about registration could cause confusion

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, makes sense.

In that case, we can just change the signature of the new_error_message function to accept a std::error::Error instead of ConversionError so that this whole function can be shortened as:

message_or_err
    .map_err(
        |error| MessageConversionError {
            error,
            topic: input.topic.name.clone(),
        })
    .unwrap_or_else(|error| self.new_error_message(error))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, you're right, so I implemented your suggestion.

Comment on lines +145 to +148
let error = MessageConversionError {
error,
topic: input.topic.name.clone(),
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, makes sense.

In that case, we can just change the signature of the new_error_message function to accept a std::error::Error instead of ConversionError so that this whole function can be shortened as:

message_or_err
    .map_err(
        |error| MessageConversionError {
            error,
            topic: input.topic.name.clone(),
        })
    .unwrap_or_else(|error| self.new_error_message(error))

Improve error reporting in c8y mapper by printing the topic when there
was an error converting a message on that topic.

Example: when publishing an invalid command metadata message:
`$ tedge mqtt pub -r te/device/main///cmd/config_snapshot 'a'`

before:
`ERROR: Mapping error: expected value at line 1 column 1`

after:
`ERROR: Mapping error: Failed to convert a message on topic 'te/device/main///cmd/config_snapshot': expected value at line 1 column 1`

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
@Bravo555 Bravo555 force-pushed the improve/c8y-converter-error-reporting branch from 6d04337 to 443ec28 Compare October 31, 2024 10:40
@Bravo555 Bravo555 temporarily deployed to Test Pull Request October 31, 2024 10:40 — with GitHub Actions Inactive
@Bravo555 Bravo555 added this pull request to the merge queue Oct 31, 2024
Merged via the queue into thin-edge:main with commit a5ee225 Oct 31, 2024
@reubenmiller reubenmiller changed the title Attach topic to c8y message conversion error feat: Attach topic to c8y message conversion error Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement User value theme:troubleshooting Theme: Troubleshooting and remote control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants