Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: More deep error messages #159

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
15 changes: 7 additions & 8 deletions util/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ func SetOsProxy(port int) error {

network, err := getDefaultNetwork()
if err != nil {
return fmt.Errorf("failed to get network interfaces, stdout: %s: %w", string(network), err)
return fmt.Errorf("failed to get network interfaces: %w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be network or network service. We extract an interface from the route command and try to find a NS that uses it.

Copy link
Author

@TeaDove TeaDove Aug 22, 2024

Choose a reason for hiding this comment

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

I rewrote it as failed to get default network, cause we are calling getDefaultNetwork.

}


args := fmt.Sprintf("'%s' 127.0.0.1 %d", network, port)

out, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+args).Output()
out, err := exec.Command("sh", "-c", "networksetup -setwebproxy "+args).Output()
if err != nil {
return fmt.Errorf("failed to set web proxy, stdout: %s: %w", string(out), err)
}


out, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+args).Output()
if err != nil {
return fmt.Errorf("failed to set secure web proxy, stdout: %s: %w", string(out), err)
Expand All @@ -46,10 +44,10 @@ func UnsetOsProxy() error {

network, err := getDefaultNetwork()
if err != nil {
return fmt.Errorf("failed to get network interfaces, stdout: %s: %w", string(network), err)
return fmt.Errorf("failed to get network interfaces: %w", err)
}

out, err = exec.Command("sh", "-c", "networksetup -setwebproxystate "+"'"+network+"'"+" off").Output()
out, err := exec.Command("sh", "-c", "networksetup -setwebproxystate "+"'"+network+"'"+" off").Output()
if err != nil {
return fmt.Errorf("failed to set web proxy, stdout: %s: %w", string(out), err)
}
Expand All @@ -65,8 +63,9 @@ func UnsetOsProxy() error {
func getDefaultNetwork() (string, error) {
network, err := exec.Command("sh", "-c", getDefaultNetworkCMD).Output()
if err != nil {
return "", err
} else if len(network) == 0 {
return "", fmt.Errorf("failed to get default network, stdout: %s: %w", string(network), err)
}
if len(network) == 0 {
return "", errors.New("no available networks")
}
return strings.TrimSpace(string(network)), nil
Expand Down