Skip to content

Conversation

@ibigbug
Copy link
Member

@ibigbug ibigbug commented May 24, 2025

🤔 This is a ...

  • New feature
  • Bug fix
  • Performance optimization
  • Enhancement feature
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

📝 Changelog

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Changelog is provided or not needed

@ibigbug ibigbug requested a review from Copilot May 24, 2025 20:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the global proxy group setup by including provider proxies, reduces duplication via two new helper functions, and adjusts error propagation and inbound handling.

  • Append provider proxies to the global proxy list instead of only using the plain provider.
  • Refactor repeated empty‐check and provider‐appending logic into check_group_empty and maybe_append_providers.
  • Change unwrap() to ? on PlainProvider::new and replace unimplemented redir case with a warning.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
clash_lib/src/app/outbound/manager.rs Added check_group_empty and maybe_append_providers, refactored duplicate code, improved error handling, and updated global selector to include all providers.
clash_lib/src/app/inbound/network_listener.rs Switched InboundOpts::Redir from unimplemented!() to a logged warning that returns early.
Comments suppressed due to low confidence (1)

clash_lib/src/app/outbound/manager.rs:389

  • New helper functions like maybe_append_providers and check_group_empty introduce important logic. Adding unit tests for these helpers would ensure they behave correctly with None, empty, and non‐existent providers.
fn maybe_append_providers(

Comment on lines +393 to +405
) {
if let Some(provider_names) = provider_names {
for provider_name in provider_names {
let provider = provider_registry
.get(provider_name)
.unwrap_or_else(|| {
print_and_exit!("provider {} not found", provider_name);
})
.clone();

providers.push(provider);
}
}
Copy link

Copilot AI May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The helper currently aborts the entire process when a provider is missing. Consider returning a Result with a descriptive error and propagating it, to keep error handling consistent instead of calling print_and_exit!.

Suggested change
) {
if let Some(provider_names) = provider_names {
for provider_name in provider_names {
let provider = provider_registry
.get(provider_name)
.unwrap_or_else(|| {
print_and_exit!("provider {} not found", provider_name);
})
.clone();
providers.push(provider);
}
}
) -> Result<(), Error> {
if let Some(provider_names) = provider_names {
for provider_name in provider_names {
let provider = provider_registry
.get(provider_name)
.ok_or_else(|| {
Error::InvalidConfig(format!("provider {} not found", provider_name))
})?
.clone();
providers.push(provider);
}
}
Ok(())

Copilot uses AI. Check for mistakes.
InboundOpts::Redir { .. } => unimplemented!(),
InboundOpts::Redir { .. } => {
warn!("redir is not implemented yet");
return Ok(());
Copy link

Copilot AI May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Silently returning Ok(()) for an unimplemented redir option may hide unexpected behavior downstream. Consider returning an explicit Err to signal that this feature is not yet supported.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented May 24, 2025

Codecov Report

Attention: Patch coverage is 10.14493% with 62 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
clash_lib/src/app/outbound/manager.rs 10.44% 59 Missing and 1 partial ⚠️
clash_lib/src/app/inbound/network_listener.rs 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ibigbug ibigbug merged commit f762b51 into master May 24, 2025
31 of 32 checks passed
@ibigbug ibigbug deleted the fix-global-proxies branch May 24, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants