-
Notifications
You must be signed in to change notification settings - Fork 59
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
Removed all unwraps/panics for all code except testing #36
Removed all unwraps/panics for all code except testing #36
Conversation
c7a7d45
to
9936736
Compare
src/secure_mount.rs
Outdated
let secure_dir = format!("{}{}", common::WORK_DIR, "/secure"); | ||
match check_mount(&secure_dir) { | ||
Ok(b) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Match on Ok(false)
and Ok(true)
rather than having an if
inside the match
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
src/secure_mount.rs
Outdated
// Create directory if the directory is not exist. The | ||
// directory permission is set to 448. | ||
if !secure_dir_path.exists() { | ||
match fs::create_dir(secure_dir_path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use an if let
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
84fc754
to
70fea43
Compare
Requested change implemented. Test passed. Ready for a review. |
70fea43
to
41ec48a
Compare
This is PR that remove all the unwrap in the code base, except the testing suite. In main, I used loop scope to wrap around the whole function, the function will exit the loop if either finish executing all the code or encounter an error. In common, the function json_response_content, which was generating a new response this function is called, is changed to set_response_content that a response is borrowed and edit its content based on the given parameters. In TPM, I simply use a match or if let to remove the unwrap, but many functions' return types are not Result which doesn't support error returning. Therefore, those functions need to be updated with Result return type in the future PR. An issue has been opened regarding this change. Test passed. Ready for a review. |
083ceee
to
91d1d4d
Compare
bafe874
to
0752ef2
Compare
Add a bash script for catching panic call in CI. Test Passed. Ready for a review. |
secure_dir | ||
); | ||
if tokens[0] != "tmpfs" { | ||
return emsg(format!("secure storage location {} already mounted on wrong file system type: {}. Unmount to continue.", secure_dir, tokens[0]).as_str(), None::<String>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way you can wrap this better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the message string too long? How about using a shorter message instead?
@@ -47,34 +48,35 @@ pub static MOUNT_SECURE: bool = true; | |||
* 2. There is no space in the json content, but python version response | |||
* content contains white space in between keys. | |||
*/ | |||
pub fn json_response_content( | |||
pub fn set_response_content( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I changed the function's implementation from creating a new response each time to modifying the response body. I think the new name is more appropriate for the function.
37b0145
to
a7fafa7
Compare
Reimplemented the GET/POST request handler in main.rs into two separate functions that are more adequate for error handling using Result. |
src/main.rs
Outdated
@@ -44,7 +46,7 @@ fn main() { | |||
info!("Starting server..."); | |||
|
|||
/* Should be port 3000 eventually */ | |||
let addr = "127.0.0.1:1337".parse().unwrap(); | |||
let addr = ([127, 0, 0, 1], 3000).into(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing port number is not in scope for this PR and would need the comment above removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed changed of port number
.travis/panic-test.sh
Outdated
|
||
# Output result | ||
if [ "$panic_line" -gt 0 ] | ||
then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes on the previous line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious. Would it cause any difference or this is what people normally do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did it yourself earlier in the file. It's also pretty normal because you get a block structure similar to C (or Rust) - "then" corresponds to "{", and "fi" to "}".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks.
.travis/panic-test.sh
Outdated
done < "$banned_function" | ||
|
||
output="" | ||
panic_line=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 isn't a good sentinel. Consider what'll happen if a banned function appears on the first line of a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to using boolean as a sentinel instead of using 0.
a7fafa7
to
063d0d9
Compare
Test Passed. Ready for a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review. You still have outstanding comments from previous review.
063d0d9
to
3d3d631
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change request
3d3d631
to
eb3b28c
Compare
eb3b28c
to
9e7d384
Compare
This code needs cleanup. [[email protected]: squash, commit message, some cleanup]
9e7d384
to
6c4f3e1
Compare
6c4f3e1
to
bc9a10a
Compare
As I am quite tired of looking at this PR; I have rewritten the checker in python and squished the results. I'm curious if you even ran the old code; Some effort will be spent going forward on a cohesive codebase cleanup. |
My apologies. Sorry for making you have this feeling. Will be more careful next time. |
Result<>
after removing the unwraps, which has better error handling..travis/
directory.The main change in main.rs is a loop scope is used to wrap around the request, once an error is encountered early exit the loop scope with the response that has the corresponding content regarding the error.
Now there should be now unwraps/panics in the repo and prevent further use of these panic function in this repo.