Skip to content

Commit

Permalink
[rust] Log error message as debug trace when parsing version
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Apr 21, 2023
1 parent 4dd9e1f commit c7e2b55
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
6 changes: 5 additions & 1 deletion rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ impl SeleniumManager for ChromeManager {
"Reading {} version from {}",
&self.driver_name, driver_url
));
match read_version_from_link(self.get_http_client(), driver_url) {
match read_version_from_link(
self.get_http_client(),
driver_url,
self.get_logger(),
) {
Ok(version) => {
driver_version = version;
break;
Expand Down
14 changes: 11 additions & 3 deletions rust/src/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ pub async fn download_driver_to_tmp_folder(
Ok((tmp_dir, target_path))
}

pub fn read_version_from_link(http_client: &Client, url: String) -> Result<String, Box<dyn Error>> {
parse_version(read_content_from_link(http_client, url)?)
pub fn read_version_from_link(
http_client: &Client,
url: String,
log: &Logger,
) -> Result<String, Box<dyn Error>> {
parse_version(read_content_from_link(http_client, url)?, log)
}

#[tokio::main]
Expand All @@ -81,6 +85,10 @@ pub async fn read_content_from_link(
pub async fn read_redirect_from_link(
http_client: &Client,
url: String,
log: &Logger,
) -> Result<String, Box<dyn Error>> {
parse_version(http_client.get(&url).send().await?.url().path().to_string())
parse_version(
http_client.get(&url).send().await?.url().path().to_string(),
log,
)
}
3 changes: 2 additions & 1 deletion rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl SeleniumManager for EdgeManager {
"Reading {} version from {}",
&self.driver_name, driver_url
));
let driver_version = read_version_from_link(self.get_http_client(), driver_url)?;
let driver_version =
read_version_from_link(self.get_http_client(), driver_url, self.get_logger())?;

if !browser_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
Expand Down
3 changes: 2 additions & 1 deletion rust/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ pub fn get_binary_extension(os: &str) -> &str {
}
}

pub fn parse_version(version_text: String) -> Result<String, Box<dyn Error>> {
pub fn parse_version(version_text: String, log: &Logger) -> Result<String, Box<dyn Error>> {
if version_text.to_ascii_lowercase().contains("error") {
log.debug(format!("Error parsing version: {}", version_text));
return Err(PARSE_ERROR.into());
}
let mut parsed_version = "".to_string();
Expand Down
3 changes: 2 additions & 1 deletion rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ impl SeleniumManager for FirefoxManager {
}
_ => {
let latest_url = format!("{}{}", DRIVER_URL, LATEST_RELEASE);
let driver_version = read_redirect_from_link(self.get_http_client(), latest_url)?;
let driver_version =
read_redirect_from_link(self.get_http_client(), latest_url, self.get_logger())?;

if !browser_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
Expand Down
6 changes: 4 additions & 2 deletions rust/src/iexplorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ impl SeleniumManager for IExplorerManager {

let index_release =
driver_url.rfind(IEDRIVER_RELEASE).unwrap() + IEDRIVER_RELEASE.len();
let driver_version =
parse_version(driver_url.as_str()[index_release..].to_string())?;
let driver_version = parse_version(
driver_url.as_str()[index_release..].to_string(),
self.get_logger(),
)?;

if !browser_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
Expand Down
5 changes: 3 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ pub trait SeleniumManager {
Ok(out) => out,
Err(_e) => continue,
};
let full_browser_version = parse_version(output).unwrap_or_default();
let full_browser_version =
parse_version(output, self.get_logger()).unwrap_or_default();
if full_browser_version.is_empty() {
continue;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ pub trait SeleniumManager {
.run_shell_command_with_log(format_one_arg(DASH_DASH_VERSION, self.get_driver_name()))
{
Ok(output) => {
let parsed_version = parse_version(output).unwrap_or_default();
let parsed_version = parse_version(output, self.get_logger()).unwrap_or_default();
if !parsed_version.is_empty() {
let which_command = if WINDOWS.is(self.get_os()) {
WHERE_COMMAND
Expand Down

0 comments on commit c7e2b55

Please sign in to comment.