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

Remove read_file_to_str helper #245

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Remove read_file_to_str helper #245

wants to merge 2 commits into from

Conversation

mxpv
Copy link
Member

@mxpv mxpv commented Feb 22, 2024

Use fs::read_to_string from stdlib/tokio instead.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
@github-actions github-actions bot added C-runc-shim Runc shim C-shim Containerd shim labels Feb 22, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (cc445f5) 38.08% compared to head (8753903) 38.02%.

Files Patch % Lines
crates/shim/src/asynchronous/util.rs 20.00% 4 Missing ⚠️
crates/runc-shim/src/runc.rs 0.00% 2 Missing ⚠️
crates/shim/src/asynchronous/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
- Coverage   38.08%   38.02%   -0.06%     
==========================================
  Files          55       55              
  Lines        5099     5086      -13     
==========================================
- Hits         1942     1934       -8     
+ Misses       3157     3152       -5     
Flag Coverage Δ
unittests 38.02% <12.50%> (-0.06%) ⬇️

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.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +87 to +88
#[error("Failed to read file: {0}")]
Io(#[from] std::io::Error),
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this type of error always be failed to read a file?

Copy link
Member

Choose a reason for hiding this comment

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

@mxpv IoError is defined in L40, I think you can use macro io_error! to map errors.
The error message in std::io::Error is not contains any info of filename, for exampe, if the file is not exist, the error would be No such file or directory without any info to indicate which file or directory is not exist, that is diffcult to debug. Thus, the macro io_error! is used for load the filename or other details, here is an example:

    let finame = "config.json";
    File::open(finame)
        .await
        .map_err(io_error!(e, "failed to open {}: ", finame))?;

and the error would be failed to open config.json error: No such file or directory

Copy link
Member Author

@mxpv mxpv Feb 23, 2024

Choose a reason for hiding this comment

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

I don't really like the requirement to map errors and use macros everywhere, like
map_err(io_error!. I feel like anyhow.Context would be a better fit here. Will investigate this more.

Copy link
Member

Choose a reason for hiding this comment

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

However, anyhow error is not easy to downcast if you need check the exact type of error

Copy link
Member Author

Choose a reason for hiding this comment

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

Where exactly we need to downcast?

Copy link
Member

Choose a reason for hiding this comment

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

Where exactly we need to downcast?

When you want to ignore some specific error.

Comment on lines +87 to +88
#[error("Failed to read file: {0}")]
Io(#[from] std::io::Error),
Copy link
Member

Choose a reason for hiding this comment

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

@mxpv IoError is defined in L40, I think you can use macro io_error! to map errors.
The error message in std::io::Error is not contains any info of filename, for exampe, if the file is not exist, the error would be No such file or directory without any info to indicate which file or directory is not exist, that is diffcult to debug. Thus, the macro io_error! is used for load the filename or other details, here is an example:

    let finame = "config.json";
    File::open(finame)
        .await
        .map_err(io_error!(e, "failed to open {}: ", finame))?;

and the error would be failed to open config.json error: No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-runc-shim Runc shim C-shim Containerd shim
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants