Skip to content

Commit

Permalink
Merge pull request #318 from gabriel-samfira/fix-nil-pointer-cli
Browse files Browse the repository at this point in the history
Fix nil pointer dereference when rendering message
  • Loading branch information
gabriel-samfira authored Dec 12, 2024
2 parents c4a7a59 + f8b4118 commit 1cb2d70
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cmd/garm-cli/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ garm-cli init --name=dev --url=https://runner.example.com --username=admin --pas
}

controllerInfoResponse, err := apiCli.Controller.UpdateController(updateUrlsReq, authToken)
renderResponseMessage(response.Payload, controllerInfoResponse.Payload, err)
renderResponseMessage(response.Payload, controllerInfoResponse, err)
return nil
},
}
Expand Down Expand Up @@ -204,10 +204,7 @@ func renderUserTable(user params.User) string {
return t.Render()
}

func renderResponseMessage(user params.User, controllerInfo params.ControllerInfo, err error) {
userTable := renderUserTable(user)
controllerInfoTable := renderControllerInfoTable(controllerInfo)

func renderResponseMessage(user params.User, controllerInfo *apiClientController.UpdateControllerOK, controllerURLUpdateErr error) {
headerMsg := `Congrats! Your controller is now initialized.
Following are the details of the admin user and details about the controller.
Expand Down Expand Up @@ -244,11 +241,13 @@ you must set them up by running:
See the help message for garm-cli controller update for more information.
`
var ctrlMsg string
if err != nil {
ctrlMsg = fmt.Sprintf(controllerErrorMsg, err)
if controllerURLUpdateErr != nil || controllerInfo == nil {
ctrlMsg = fmt.Sprintf(controllerErrorMsg, controllerURLUpdateErr)
} else {
controllerInfoTable := renderControllerInfoTable(controllerInfo.Payload)
ctrlMsg = fmt.Sprintf(controllerMsg, controllerInfoTable)
}

userTable := renderUserTable(user)
fmt.Printf("%s\n%s\n", fmt.Sprintf(headerMsg, userTable), ctrlMsg)
}

0 comments on commit 1cb2d70

Please sign in to comment.