Skip to content

Commit 738f856

Browse files
committed
fix(tls): replace unimplemented!() with proper error for TLS resolver
- Add ResolverNotSupported error variant to TlsError enum - Replace unimplemented!() panics with proper error returns in create_client_config - Improves error handling by returning graceful errors instead of panicking fix(tsc): improve error message for invalid 'this' parameter syntax - Add helpful error message rewrite for TS2684 (invalid 'this' parameter) - Provides guidance on correct React/Preact component typing syntax - Helps users understand the difference between 'this' parameter and function return types
1 parent 3c0f289 commit 738f856

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cli/tsc/go.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ fn maybe_rewrite_message(message: String, code: u64) -> String {
182182
format!(
183183
"Property '{name}' does not exist on type 'typeof Deno'. 'Deno.{name}' is an unstable API. If not, try changing the 'lib' compiler option to include 'deno.unstable' or add a triple-slash directive to the top of your entrypoint (main file): /// <reference lib=\"deno.unstable\" />",
184184
)
185+
} else if code == 2684 && message.contains("'this' parameter") {
186+
format!(
187+
"{}\n\nNote: The 'this' parameter is used to type the 'this' context, not the function return type. If you're trying to type a React/Preact component, use:\n const Component: FC<Props> = (props) => {{ ... }}\nor:\n function Component(props: Props): JSX.Element {{ ... }}",
188+
message
189+
)
185190
} else {
186191
message
187192
}

ext/tls/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub enum TlsError {
5151
#[class("InvalidData")]
5252
#[error("Unable to decode key")]
5353
KeyDecode,
54+
#[class("NotSupported")]
55+
#[error("TLS key resolver is not supported for client connections")]
56+
ResolverNotSupported,
5457
}
5558

5659
/// Lazily resolves the root cert store.
@@ -310,7 +313,9 @@ pub fn create_client_config(
310313
.with_client_auth_cert(cert_chain, private_key.clone_key())
311314
.expect("invalid client key or certificate"),
312315
TlsKeys::Null => client_config.with_no_client_auth(),
313-
TlsKeys::Resolver(_) => unimplemented!(),
316+
TlsKeys::Resolver(_) => {
317+
return Err(TlsError::ResolverNotSupported);
318+
}
314319
};
315320

316321
add_alpn(&mut client, socket_use);
@@ -343,7 +348,9 @@ pub fn create_client_config(
343348
.with_client_auth_cert(cert_chain, private_key.clone_key())
344349
.expect("invalid client key or certificate"),
345350
TlsKeys::Null => client_config.with_no_client_auth(),
346-
TlsKeys::Resolver(_) => unimplemented!(),
351+
TlsKeys::Resolver(_) => {
352+
return Err(TlsError::ResolverNotSupported);
353+
}
347354
};
348355

349356
add_alpn(&mut client, socket_use);

0 commit comments

Comments
 (0)