diff --git a/src-tauri/grpc/src/manager.rs b/src-tauri/grpc/src/manager.rs index 68f47da1..fe9edd47 100644 --- a/src-tauri/grpc/src/manager.rs +++ b/src-tauri/grpc/src/manager.rs @@ -189,7 +189,7 @@ impl GrpcHandle { paths: Vec, ) -> Result, String> { let pool = fill_pool_from_files(&self.app_handle, paths).await?; - let uri = Uri::from_str(uri).map_err(|e| e.to_string())?; + let uri = uri_from_str(uri)?; self.pools.insert(self.get_pool_key(id, &uri), pool.clone()); Ok(self.services_from_pool(&pool)) } @@ -198,7 +198,7 @@ impl GrpcHandle { id: &str, uri: &str, ) -> Result, String> { - let uri = Uri::from_str(uri).map_err(|e| e.to_string())?; + let uri = uri_from_str(uri)?; let pool = fill_pool(&uri).await?; self.pools.insert(self.get_pool_key(id, &uri), pool.clone()); Ok(self.services_from_pool(&pool)) @@ -239,7 +239,7 @@ impl GrpcHandle { uri: &str, proto_files: Vec, ) -> Result { - let uri = Uri::from_str(uri).map_err(|e| e.to_string())?; + let uri = uri_from_str(uri)?; let pool = match self.pools.get(id) { Some(p) => p.clone(), None => match proto_files.len() { @@ -267,3 +267,13 @@ fn decorate_req(metadata: HashMap, req: &mut Request) -> R } Ok(()) } + +fn uri_from_str(uri_str: &str) -> Result { + match Uri::from_str(uri_str) { + Ok(uri) => Ok(uri), + Err(err) => { + // Uri::from_str basically only returns "invalid format" so we add more context here + Err(format!("Failed to parse URL, {}", err.to_string())) + }, + } +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 455154df..f08af614 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -134,6 +134,12 @@ async fn cmd_grpc_reflect( let req = get_grpc_request(&window, request_id) .await .map_err(|e| e.to_string())?; + + // Short-circuit if no URL is set + if req.url.is_empty() { + return Ok(Vec::new()); + } + let uri = safe_uri(req.url.as_str()); if proto_files.len() > 0 { grpc_handle diff --git a/src-web/components/GrpcProtoSelection.tsx b/src-web/components/GrpcProtoSelection.tsx index c8755c0c..a594fad1 100644 --- a/src-web/components/GrpcProtoSelection.tsx +++ b/src-web/components/GrpcProtoSelection.tsx @@ -5,7 +5,6 @@ import { useGrpcRequest } from '../hooks/useGrpcRequest'; import { count } from '../lib/pluralize'; import { Banner } from './core/Banner'; import { Button } from './core/Button'; -import { FormattedError } from './core/FormattedError'; import { IconButton } from './core/IconButton'; import { InlineCode } from './core/InlineCode'; import { Link } from './core/Link'; @@ -129,7 +128,14 @@ export function GrpcProtoSelection({ requestId }: Props) { )} - {reflectError && {reflectError}} + {reflectError && ( + +

+ Reflection failed on URL {request.url} +

+ {reflectError} +
+ )} {reflectionUnimplemented && protoFiles.length === 0 && ( {request.url} doesn't implement{' '}