Skip to content

Commit

Permalink
non main exits
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Nov 22, 2021
1 parent 2b521bd commit 4480dd2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (c *CLab) createNodeCfg(nodeName string, nodeDef *types.NodeDefinition, idx
// NewLink initializes a new link object
func (c *CLab) NewLink(l *types.LinkConfig) *types.Link {
if len(l.Endpoints) != 2 {
log.Fatalf("endpoint %q has wrong syntax, unexpected number of items", l.Endpoints)
log.Fatalf("endpoint %q has wrong syntax, unexpected number of items", l.Endpoints) // skipcq: RVV-A0003
}

return &types.Link{
Expand All @@ -307,14 +307,14 @@ func (c *CLab) NewEndpoint(e string) *types.Endpoint {
// split the string to get node name and endpoint name
split := strings.Split(e, ":")
if len(split) != 2 {
log.Fatalf("endpoint %s has wrong syntax", e) // skipcq: GO-S0904
log.Fatalf("endpoint %s has wrong syntax", e) // skipcq: GO-S0904, RVV-A0003
}
nName := split[0] // node name

// initialize the endpoint name based on the split function
endpoint.EndpointName = split[1] // endpoint name
if len(endpoint.EndpointName) > 15 {
log.Fatalf("interface '%s' name exceeds maximum length of 15 characters", endpoint.EndpointName)
log.Fatalf("interface '%s' name exceeds maximum length of 15 characters", endpoint.EndpointName) //skipcq: RVV-A0003
}
// generate unique MAC
endpoint.MAC = utils.GenMac(ClabOUI)
Expand Down Expand Up @@ -350,7 +350,7 @@ func (c *CLab) NewEndpoint(e string) *types.Endpoint {
// stop the deployment if the matching node element was not found
// "host" node name is an exception, it may exist without a matching node
if endpoint.Node == nil {
log.Fatalf("not all nodes are specified in the 'topology.nodes' section or the names don't match in the 'links.endpoints' section: %s", nName) // skipcq: GO-S0904
log.Fatalf("not all nodes are specified in the 'topology.nodes' section or the names don't match in the 'links.endpoints' section: %s", nName) // skipcq: GO-S0904, RVV-A0003
}

return endpoint
Expand Down
2 changes: 1 addition & 1 deletion clab/config/transport/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (t *SSHTransport) Run(command string, timeout int) *SSHReply {
}

if ret.result == "" && ret.prompt == "" {
log.Fatalf("received zero?")
log.Error("received zero?")
continue
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var rootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
os.Exit(1) //skipcq: RVV-A0003
}
}

Expand Down
11 changes: 7 additions & 4 deletions cmd/verUpgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package cmd

import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
Expand All @@ -22,11 +22,11 @@ var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: "upgrade containerlab to latest available version",
PreRunE: sudoCheck,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
f, err := ioutil.TempFile("", "containerlab")
defer os.Remove(f.Name())
if err != nil {
log.Fatalf("Failed to create temp file %s\n", err)
return fmt.Errorf("failed to create temp file: %w", err)
}
_ = downloadFile(downloadURL, f)

Expand All @@ -36,8 +36,10 @@ var upgradeCmd = &cobra.Command{
c.Stderr = os.Stderr
err = c.Run()
if err != nil {
log.Fatalf("Upgrade failed: %s\n", err)
return fmt.Errorf("upgrade failed: %w", err)
}

return nil
},
}

Expand All @@ -55,6 +57,7 @@ func downloadFile(url string, file *os.File) error {
if err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 4480dd2

Please sign in to comment.