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

fix(cpu-template-helper): Fix error message display #4616

Merged
merged 3 commits into from
May 17, 2024

Conversation

zulinx86
Copy link
Contributor

@zulinx86 zulinx86 commented May 14, 2024

Changes

  • Don't show diff twice.
  • Handle a new line correctly in error message.

Reason

Before

$ build/cargo_target/x86_64-unknown-linux-musl/debug/cpu-template-helper fingerprint compare --prev tests/data/cpu_template_helpe
r/fingerprint_INTEL_SKYLAKE_5.10host.json --curr tests/data/cpu_template_helper/fingerprint_INTEL_SKYLAKE_6.1host.json 
Difference detected between source and target: \n{
  "name": "kernel_version",
  "prev": "5.10.215-203.850.amzn2.x86_64",
  "curr": "6.1.84-99.169.amzn2023.x86_64"
}
Error: FingerprintCompare(DiffDetected("{\n  \"name\": \"kernel_version\",\n  \"prev\": \"5.10.215-203.850.amzn2.x86_64\",\n  \"curr\": \"6.1.84-99.169.amzn2023.x86_64\"\n}"))

After

$ build/cargo_target/x86_64-unknown-linux-musl/debug/cpu-template-helper fingerprint compare --prev tests/data/cpu_template_helper/fingerprint_INTEL_SKYLAKE_5.10host.json --curr tests/data/cpu_template_helper/fingerprint_INTEL_SKYLAKE_6.1host.json 
Difference detected between source and target:
{
  "name": "kernel_version",
  "prev": "5.10.215-203.850.amzn2.x86_64",
  "curr": "6.1.84-99.169.amzn2023.x86_64"
}

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • [ ] If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • [ ] Any required documentation changes (code and docs) are included in this
    PR.
  • [ ] API changes follow the Runbook for Firecracker API changes.
  • [ ] User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • [ ] New TODOs link to an issue.
  • Commits meet
    contribution quality standards.

  • This functionality cannot be added in rust-vmm.

The CPU template helper tool showed its error message twice as follows:
```
$cpu-template-helper fingerprint compare --prev A.json --curr B.json
Difference detected between source and target:\\n{
  "name": "kernel_version",
  "prev": "5.10.215-203.850.amzn2.x86_64",
  "curr": "6.1.84-99.169.amzn2023.x86_64"
}
Error: FingerprintCompare(DiffDetected("{\n  \"name\": \"kernel_..."))
```

It is because it returned `Result` from `main()` to return an exit code
and it shows its error message on error. Instead just return the exit
code using `std::process::exit()`.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Copy link

codecov bot commented May 14, 2024

Codecov Report

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

Project coverage is 82.14%. Comparing base (afad05d) to head (70b6897).

Files Patch % Lines
src/cpu-template-helper/src/main.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4616   +/-   ##
=======================================
  Coverage   82.14%   82.14%           
=======================================
  Files         255      255           
  Lines       31282    31285    +3     
=======================================
+ Hits        25697    25700    +3     
  Misses       5585     5585           
Flag Coverage Δ
4.14-c5n.metal 79.64% <57.14%> (+<0.01%) ⬆️
4.14-c7g.metal ?
4.14-m5n.metal 79.63% <57.14%> (-0.01%) ⬇️
4.14-m6a.metal 78.86% <57.14%> (+<0.01%) ⬆️
4.14-m6g.metal 76.70% <57.14%> (+<0.01%) ⬆️
4.14-m6i.metal 79.62% <57.14%> (-0.01%) ⬇️
4.14-m7g.metal 76.70% <57.14%> (+<0.01%) ⬆️
5.10-c5n.metal 82.16% <57.14%> (+<0.01%) ⬆️
5.10-c7g.metal ?
5.10-m5n.metal 82.14% <57.14%> (-0.01%) ⬇️
5.10-m6a.metal 81.45% <57.14%> (+<0.01%) ⬆️
5.10-m6g.metal 79.47% <57.14%> (+<0.01%) ⬆️
5.10-m6i.metal 82.14% <57.14%> (+<0.01%) ⬆️
5.10-m7g.metal 79.47% <57.14%> (+<0.01%) ⬆️
6.1-c5n.metal 82.15% <57.14%> (-0.01%) ⬇️
6.1-c7g.metal ?
6.1-m5n.metal 82.14% <57.14%> (-0.01%) ⬇️
6.1-m6a.metal 81.45% <57.14%> (+<0.01%) ⬆️
6.1-m6g.metal 79.46% <57.14%> (-0.01%) ⬇️
6.1-m6i.metal 82.14% <57.14%> (-0.01%) ⬇️
6.1-m7g.metal 79.47% <57.14%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zulinx86 zulinx86 force-pushed the fix_display_error branch 2 times, most recently from 04dc7f6 to 31e738a Compare May 15, 2024 07:25
@zulinx86 zulinx86 self-assigned this May 15, 2024
@zulinx86 zulinx86 added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label May 15, 2024
Copy link
Contributor

@roypat roypat left a comment

Choose a reason for hiding this comment

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

I think generally in Rust, one should avoid using std::process::exit (https://stackoverflow.com/questions/39228685/when-is-stdprocessexit-o-k-to-use) because it interferes with dropping and unwinding. I don't think it really matters here, because its the very end of main, but maybe it's still nice to return ExitCode instead, just in case?

src/cpu-template-helper/src/main.rs Outdated Show resolved Hide resolved
src/cpu-template-helper/src/main.rs Outdated Show resolved Hide resolved
src/cpu-template-helper/src/main.rs Outdated Show resolved Hide resolved
@zulinx86
Copy link
Contributor Author

I think generally in Rust, one should avoid using std::process::exit (https://stackoverflow.com/questions/39228685/when-is-stdprocessexit-o-k-to-use) because it interferes with dropping and unwinding. I don't think it really matters here, because its the very end of main, but maybe it's still nice to return ExitCode instead, just in case?

I really love it. will apply thanks!

`displaydoc::Display` doesn't recognize `\n` as a new line in doc
string:
```
Difference detected between source and target: \n{
  "name": "kernel_version",
  "prev": "5.10.215-203.850.amzn2.x86_64",
  "curr": "6.1.84-99.169.amzn2023.x86_64"
}
```
Also, it doesn't support multi-line string unless we use `/** */` style
doc, however the doc style is denied by our format check.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
@roypat roypat merged commit 3853362 into firecracker-microvm:main May 17, 2024
6 of 7 checks passed
@zulinx86 zulinx86 deleted the fix_display_error branch May 18, 2024 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants