Conversation
m4b
left a comment
There was a problem hiding this comment.
The unwraps need to be addressed, before can consider to merge. Additionally, it may be more idiomatic to have this be a version method on a MachO, and returns an Optional<Version>; I don't think we have anywhere else where we have a From method on MachO that returns some type, so it might be a little undiomatic in this crate to do that.
| Mach::Fat(f) => { | ||
| match f | ||
| .find(|r| { | ||
| r.unwrap().cputype |
There was a problem hiding this comment.
can this unwrap panic (i.e., can a malformed or whatever binary cause this unwrap to panic?); if not please add documentation explaining why not
| == match env::var("CARGO_CFG_TARGET_ARCH").as_deref() { | ||
| Ok("x86_64") => CPU_TYPE_X86_64, | ||
| Ok("aarch64") => CPU_TYPE_ARM64, | ||
| _ => panic!("unknown arch"), |
There was a problem hiding this comment.
this definitely seems like it can panic
| } | ||
|
|
||
| impl From<Mach<'_>> for Version { | ||
| fn from(b: Mach) -> Self { |
There was a problem hiding this comment.
so there are multiple unwraps in this function, which indicates to me the choice of From is not correct; TryFrom is probably a better choice, or if you need a parsing context, it would be more idiomatic in this crate to use scroll's TryFromCtx
| impl FromStr for Version { | ||
| type Err = Error; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { |
There was a problem hiding this comment.
all these unwraps need to be map_err'd or documented why they cannot fail
| CommandVariant::BuildVersion(v) => Some(v.minos), | ||
| _ => None, | ||
| }) | ||
| .unwrap(); |
There was a problem hiding this comment.
ditto, unwrap again, needs documentation why it is infallible, or choice TryFrom/TryFromCtx, etc.
Possible implementation for #514