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

Remove redundant return statements #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions tools/catch-catchpoint/catch-catchpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,33 @@ func main() {

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("Error reading body: %v", err)
return
log.Fatalf("Error reading body: %v", err)
}

var result map[string]interface{}

err = json.Unmarshal(bodyBytes, &result)
if err != nil {
log.Fatalf("Error unmarshalling JSON: %v", err)
return
}

if lastCatchpoint, ok := result["last-catchpoint"]; ok {
catchpoint, ok := lastCatchpoint.(string)
if !ok {
log.Fatal("Error: last-catchpoint is not a string")
return
log.Fatalf("Error: last-catchpoint is not a string. %v", catchpoint)
}

var catchpointRound int
catchpointParts := strings.Split(catchpoint, "#")
if len(catchpointParts) > 0 {
catchpointRound, err = strconv.Atoi(catchpointParts[0])
if err != nil {
log.Fatal("Error: catchpoint round is not an integer")
return
log.Fatalf("Error: catchpoint round is not an integer. %v", err)
}
catchpointRoundStr := strconv.Itoa(catchpointRound)
log.Printf("Catchpoint round: %s", catchpointRoundStr)
} else {
log.Fatal("Error: catchpoint does not contain '#'")
log.Fatalf("Error: catchpoint does not contain '#'. %v", catchpointParts)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant return statement after log.Fatalf.

While the error handling change is good, there's a redundant return statement after log.Fatalf at line 143. Since log.Fatalf terminates the program, this return statement will never be executed.

Apply this diff to remove the redundant return:

 if err != nil {
   log.Fatalf("Error running command: %v", err)
-  return
 }

Also applies to: 143-143

}

lastNodeRound, _ := getLastNodeRound(pu)
Expand All @@ -124,8 +120,7 @@ func main() {
if lastRound, ok := result["last-round"].(float64); ok {
lastNetworkRound = int(lastRound)
} else {
log.Println("last-round not found in the response or is not a float64")
return
log.Fatalf("last-round not found in the response or is not a float64. %v", lastNetworkRound)
}

log.Printf("Last node round: %d, Last network round: %d\n", lastNodeRound, lastNetworkRound)
Expand All @@ -142,7 +137,6 @@ func main() {
_, err = pu.ExecuteCommand(goalCmd, "-d", algodDataDir, "node", "catchup", catchpoint)
if err != nil {
log.Fatalf("Error running command: %v", err)
return
}
} else {
log.Print("last-catchpoint not found in the response")
Expand Down
Loading