Skip to content

Commit

Permalink
fix(firewall): missing error when not setting port for tcp rule (#734)
Browse files Browse the repository at this point in the history
Switch cases don't fall through by default in Go, which lead to there
being no user-friendly error emitted when the user attempts to create a
TCP rule without specifying a port.

Related to #733
  • Loading branch information
phm07 authored Apr 19, 2024
1 parent da1b684 commit c5ad470
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions internal/cmd/firewall/add_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ var AddRuleCmd = base.Cmd{
}

switch rule.Protocol {
case hcloud.FirewallRuleProtocolTCP:
case hcloud.FirewallRuleProtocolUDP:
case hcloud.FirewallRuleProtocolUDP, hcloud.FirewallRuleProtocolTCP:
if port == "" {
return fmt.Errorf("port is required")
return fmt.Errorf("port is required (--port)")
}
default:
if port != "" {
Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/firewall/delete_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ var DeleteRuleCmd = base.Cmd{
}

switch rule.Protocol {
case hcloud.FirewallRuleProtocolTCP:
case hcloud.FirewallRuleProtocolUDP:
case hcloud.FirewallRuleProtocolTCP, hcloud.FirewallRuleProtocolUDP:
if port == "" {
return fmt.Errorf("port is required")
return fmt.Errorf("port is required (--port)")
}
default:
if port != "" {
Expand Down

0 comments on commit c5ad470

Please sign in to comment.