Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Simplify entity registration code flow #2884

Merged

Conversation

albinsuresh
Copy link
Contributor

@albinsuresh albinsuresh commented May 16, 2024

Proposed changes

Refactor the entity registration and auto registration code for simplicity and improved readability.

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

@@ -3176,28 +3188,6 @@ pub(crate) mod tests {
}
}

#[tokio::test]
async fn try_auto_registration_on_custom_topic() -> Result<(), anyhow::Error> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test isn't valid anymore, since caching of unregistered entity data as "pending entity data" was implemented.

Copy link
Contributor

github-actions bot commented May 16, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
440 0 3 440 100 1h1m11.111427s

Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 79.16667% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 78.0%. Comparing base (b3c84af) to head (c53e14a).
Report is 10 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
crates/extensions/c8y_mapper_ext/src/converter.rs 83.6% <79.1%> (-0.4%) ⬇️

... and 13 files with indirect coverage changes

Comment on lines +988 to +992
Err(anyhow!(
"Invalid entity registration message received on topic: {}",
message.topic.name
)
.into())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of this, I'd like to update EntityRegistrationMessage::try_from to return a proper error. It is currently returning () as the error type, which is weird. Not quite sure it was done like that in the past. I'm assuming there was some concrete reason behind it.

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to update EntityRegistrationMessage::try_from to return a proper error.

I vote for it.

The current error is translated to ConversionError::UnexpectedError eventually, but I think receiving invalid entity registration message is not really "unexpected". For example, if someone publishes to the topic te/custom/four/segments/topic, the current code goes to this error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to update EntityRegistrationMessage::try_from to return a proper error.

Indeed, better.

Copy link
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Thanks Albin, looks very good. Now much easier to understand.

Comment on lines +988 to +992
Err(anyhow!(
"Invalid entity registration message received on topic: {}",
message.topic.name
)
.into())
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to update EntityRegistrationMessage::try_from to return a proper error.

I vote for it.

The current error is translated to ConversionError::UnexpectedError eventually, but I think receiving invalid entity registration message is not really "unexpected". For example, if someone publishes to the topic te/custom/four/segments/topic, the current code goes to this error.

@albinsuresh albinsuresh force-pushed the refactor-entity-registration branch from 6cbe758 to c53e14a Compare May 23, 2024 11:32
@albinsuresh albinsuresh added this pull request to the merge queue May 23, 2024
Merged via the queue into thin-edge:main with commit 04abcb7 May 23, 2024
32 checks passed
@albinsuresh albinsuresh deleted the refactor-entity-registration branch May 30, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants