Skip to content

Commit

Permalink
Fix extract_version_from_yarn_lock unwrap errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marschattha committed Feb 11, 2025
1 parent b7ea577 commit 14f139d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions qlty-cli/src/initializer/scanner/package_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ impl NodePackageFile {
plugin_name: &str,
) -> Result<String> {
let package_file_data = serde_json::from_str::<Value>(package_file_contents)?;
let package_file_data = package_file_data.as_object().unwrap();
let package_file_data = if let Some(package_data) = package_file_data.as_object() {
package_data
} else {
bail!("Invalid package file data");
};

let package_file_version = Self::package_file_version(plugin_name, package_file_data)?;

Expand All @@ -99,9 +103,11 @@ impl NodePackageFile {
let mut tokens = line.split_whitespace();

if version_on_next_line {
tokens.next().unwrap(); // first token is just "version"
tokens.next(); // first token is just "version"

return Ok(tokens.next().unwrap().replace('"', ""));
if let Some(version) = tokens.next() {
return Ok(version.replace('"', ""));
}
}

let potential_package_name = tokens.next().unwrap_or_default().replace([':', '"'], "");
Expand Down

0 comments on commit 14f139d

Please sign in to comment.