Skip to content

Rework unwrap() call in persistence #1941

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

Merged
merged 1 commit into from
Jan 9, 2023

Conversation

andrei-21
Copy link
Contributor

@andrei-21 andrei-21 commented Jan 7, 2023

Use idiomatic Result::map_err() and Option::ok_or_else() instead of naked unwrap().

@andrei-21 andrei-21 force-pushed the feature/rework-unwrap branch from 9e52f3e to 66046a7 Compare January 7, 2023 21:31
@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2023

Codecov Report

Base: 90.74% // Head: 90.72% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (a320ebc) compared to base (d8a20ed).
Patch coverage: 69.23% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1941      +/-   ##
==========================================
- Coverage   90.74%   90.72%   -0.03%     
==========================================
  Files          96       96              
  Lines       50133    50135       +2     
  Branches    50133    50135       +2     
==========================================
- Hits        45493    45483      -10     
- Misses       4640     4652      +12     
Impacted Files Coverage Δ
lightning-persister/src/lib.rs 92.66% <69.23%> (-0.80%) ⬇️
lightning/src/chain/onchaintx.rs 94.33% <0.00%> (-1.05%) ⬇️
lightning/src/util/events.rs 29.35% <0.00%> (-0.23%) ⬇️
lightning/src/ln/functional_tests.rs 96.97% <0.00%> (-0.09%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Nice, thanks.

let filename = owned_file_name.to_str();
if !filename.is_some() || !filename.unwrap().is_ascii() || filename.unwrap().len() < 65 {
let filename = owned_file_name.to_str()
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidData,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please indent with a single tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. It is a work for fmt of course... ;)

if !filename.is_some() || !filename.unwrap().is_ascii() || filename.unwrap().len() < 65 {
let filename = owned_file_name.to_str()
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidData,
"File name is not a valid utf8 string"))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, no need to push this to the end of the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@andrei-21 andrei-21 force-pushed the feature/rework-unwrap branch from 66046a7 to a320ebc Compare January 8, 2023 11:26
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Nice one!

@TheBlueMatt TheBlueMatt merged commit 197a47a into lightningdevkit:main Jan 9, 2023
@andrei-21 andrei-21 deleted the feature/rework-unwrap branch January 9, 2023 19:46
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.

5 participants