Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions core/src/backend/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,7 @@

/// This creates and returns the generic ErrorResponse for an invalid URL
/// used in the NavigatorBackend fetch methods.
pub fn create_fetch_error<ErrorType: Display>(
url: &str,
error: ErrorType,
) -> Result<Box<dyn SuccessResponse>, ErrorResponse> {
pub fn create_fetch_error<ErrorType: Display>(url: &str, error: ErrorType) -> ErrorResponse {

Check warning on line 462 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (462)
create_specific_fetch_error("Invalid URL", url, error)
}

Expand All @@ -472,17 +469,17 @@
reason: &str,
url: &str,
error: ErrorType,
) -> Result<Box<dyn SuccessResponse>, ErrorResponse> {
) -> ErrorResponse {

Check warning on line 472 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (472)
let message = if error.to_string() == "" {
format!("{reason} {url}")
} else {
format!("{reason} {url}: {error}")
};
let error = Error::FetchError(message);
Err(ErrorResponse {
ErrorResponse {

Check warning on line 479 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (479)
url: url.to_string(),
error,
})
}

Check warning on line 482 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (482)
}

// Url doesn't implement from_file_path and to_file_path for WASM targets.
Expand Down Expand Up @@ -624,7 +621,7 @@

let url = match navigator.resolve_url(url) {
Ok(url) => url,
Err(e) => return async_return(create_fetch_error(url, e)),
Err(e) => return async_return(Err(create_fetch_error(url, e))),

Check warning on line 624 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (624)
};
let path = if url.scheme() == "file" {
// Flash supports query parameters with local urls.
Expand All @@ -636,11 +633,11 @@
match url_to_file_path(&filesystem_url) {
Ok(path) => path,
Err(_) => {
return async_return(create_specific_fetch_error(
return async_return(Err(create_specific_fetch_error(

Check warning on line 636 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (636)
"Unable to create path out of URL",
url.as_str(),
"",
))
)))

Check warning on line 640 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (640)
}
}
} else if let Some(base_path) = base_path {
Expand All @@ -654,11 +651,11 @@
}
path
} else {
return async_return(create_specific_fetch_error(
return async_return(Err(create_specific_fetch_error(

Check warning on line 654 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (654)
&format!("{navigator_name} can't fetch non-local URL"),
url.as_str(),
"",
));
)));

Check warning on line 658 in core/src/backend/navigator.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (658)
};

Box::pin(async move {
Expand Down
2 changes: 1 addition & 1 deletion frontend-utils/src/backends/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<F: FutureSpawner + 'static, I: NavigatorInterface> NavigatorBackend
let mut processed_url = match self.resolve_url(request.url()) {
Ok(url) => url,
Err(e) => {
return async_return(create_fetch_error(request.url(), e));
return async_return(Err(create_fetch_error(request.url(), e)));
}
};

Expand Down
2 changes: 1 addition & 1 deletion tests/framework/src/backends/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl NavigatorBackend for TestNavigatorBackend {

let url = match self.resolve_url(request.url()) {
Ok(url) => url,
Err(e) => return async_return(create_fetch_error(request.url(), e)),
Err(e) => return async_return(Err(create_fetch_error(request.url(), e))),
};

let base_path = self.relative_base_path.clone();
Expand Down
46 changes: 18 additions & 28 deletions web/src/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,7 @@ impl NavigatorBackend for WebNavigatorBackend {
}

let url = match self.resolve_url(url) {
Ok(url) => {
if url.scheme() == "file" {
tracing::error!(
"Can't open the local URL {} on WASM target",
url.to_string()
);
return;
} else {
url
}
}
Ok(url) => url,
Err(e) => {
tracing::error!(
"Could not parse URL because of {}, the corrupt URL was: {}",
Expand Down Expand Up @@ -307,19 +297,9 @@ impl NavigatorBackend for WebNavigatorBackend {

fn fetch(&self, request: Request) -> OwnedFuture<Box<dyn SuccessResponse>, ErrorResponse> {
let url = match self.resolve_url(request.url()) {
Ok(url) => {
if url.scheme() == "file" {
return async_return(create_specific_fetch_error(
"WASM target can't fetch local URL",
url.as_str(),
"",
));
} else {
url
}
}
Ok(url) => url,
Err(e) => {
return async_return(create_fetch_error(request.url(), e));
return async_return(Err(create_fetch_error(request.url(), e)));
}
};

Expand Down Expand Up @@ -366,11 +346,11 @@ impl NavigatorBackend for WebNavigatorBackend {
let web_request = match WebRequest::new_with_str_and_init(url.as_str(), &init) {
Ok(web_request) => web_request,
Err(_) => {
return create_specific_fetch_error(
return Err(create_specific_fetch_error(
"Unable to create request for",
url.as_str(),
"",
);
));
}
};

Expand All @@ -388,9 +368,19 @@ impl NavigatorBackend for WebNavigatorBackend {
let window = web_sys::window().expect("window()");
let fetchval = JsFuture::from(window.fetch_with_request(&web_request))
.await
.map_err(|_| ErrorResponse {
url: url.to_string(),
error: Error::FetchError("Got JS error".to_string()),
.map_err(|_| {
if url.scheme() == "file" {
create_specific_fetch_error(
"WASM target can't fetch local URL",
url.as_str(),
"",
)
} else {
ErrorResponse {
url: url.to_string(),
error: Error::FetchError("Got JS error".to_string()),
}
}
})?;

let response: WebResponse = fetchval.dyn_into().map_err(|_| ErrorResponse {
Expand Down
Loading