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

Better message when no data returned #153

Merged
merged 2 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
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: 8 additions & 8 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ var getProjectCmd = &cobra.Command{
os.Exit(1)
}
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("No details for project '%s'", getProjectFlags.Project), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand All @@ -89,8 +89,8 @@ var getDeploymentCmd = &cobra.Command{
os.Exit(1)
}
if string(returnedJSON) == "null" {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("No deployment for remoteId '%s'", getProjectFlags.RemoteID), outputOptions)
os.Exit(0)
}
var deployment api.Deployment
err = json.Unmarshal([]byte(returnedJSON), &deployment)
Expand Down Expand Up @@ -123,8 +123,8 @@ var getEnvironmentCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("No environment '%s' for project '%s'", cmdProjectEnvironment, cmdProjectName), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand All @@ -148,8 +148,8 @@ var getProjectKeyCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("No project-key for project '%s'", getProjectFlags.Project), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand Down
40 changes: 24 additions & 16 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ var listProjectsCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo("No access to any projects in Lagoon", outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand All @@ -69,8 +69,8 @@ var listGroupsCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo("This account is not in any groups", outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand Down Expand Up @@ -101,8 +101,12 @@ var listGroupProjectsCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
if !listAllProjects {
output.RenderInfo(fmt.Sprintf("There are no projects in group '%s'", groupName), outputOptions)
} else {
output.RenderInfo("There are no projects in any groups", outputOptions)
}
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand All @@ -125,8 +129,8 @@ var listProjectCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("There are no environments for project '%s'", cmdProjectName), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand Down Expand Up @@ -156,8 +160,12 @@ var listVariablesCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
if cmdProjectEnvironment != "" {
output.RenderInfo(fmt.Sprintf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName), outputOptions)
} else {
output.RenderInfo(fmt.Sprintf("There are no variables for project '%s'", cmdProjectName), outputOptions)
}
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)
},
Expand All @@ -180,8 +188,8 @@ var listDeploymentsCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("There are no deployments for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)
},
Expand All @@ -204,8 +212,8 @@ var listTasksCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("There are no tasks for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)
},
Expand All @@ -225,8 +233,8 @@ var listUsersCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo("There are no users in any groups", outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand Down
10 changes: 7 additions & 3 deletions cmd/notificationsrocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ var listRocketChatsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
var returnedJSON []byte
var err error
var notificationFlags NotificationFlags
if listAllProjects {
returnedJSON, err = pClient.ListAllRocketChats()
handleError(err)
} else {
notificationFlags := parseNotificationFlags(*cmd.Flags())
notificationFlags = parseNotificationFlags(*cmd.Flags())
if notificationFlags.Project == "" {
fmt.Println("Missing arguments: Project name is not defined")
cmd.Help()
Expand All @@ -34,8 +35,11 @@ var listRocketChatsCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
if listAllProjects {
output.RenderInfo("No notifications for RocketChat", outputOptions)
} else {
output.RenderInfo(fmt.Sprintf("No notifications for RocketChat in project '%s'", notificationFlags.Project), outputOptions)
}
}
output.RenderOutput(dataMain, outputOptions)
},
Expand Down
11 changes: 8 additions & 3 deletions cmd/notificationsslack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ var listSlackCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
var returnedJSON []byte
var err error
var notificationFlags NotificationFlags
if listAllProjects {
returnedJSON, err = pClient.ListAllSlacks()
handleError(err)
} else {
notificationFlags := parseNotificationFlags(*cmd.Flags())
notificationFlags = parseNotificationFlags(*cmd.Flags())
if notificationFlags.Project == "" {
fmt.Println("Missing arguments: Project name is not defined")
cmd.Help()
Expand All @@ -35,8 +36,12 @@ var listSlackCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
if listAllProjects {
output.RenderInfo("No notifications for Slack", outputOptions)
} else {
output.RenderInfo(fmt.Sprintf("No notifications for Slack in project '%s'", notificationFlags.Project), outputOptions)
}
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand Down
2 changes: 0 additions & 2 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ var outputOptions = output.Options{

var debugEnable bool

var noDataError = "no data returned from the lagoon api"

func handleError(err error) {
if err != nil {
output.RenderError(err.Error(), outputOptions)
Expand Down
8 changes: 4 additions & 4 deletions cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ var getUserKeysCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo(fmt.Sprintf("No ssh-keys for user '%s'", userEmail), outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand All @@ -242,8 +242,8 @@ var getAllUserKeysCmd = &cobra.Command{
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
handleError(err)
if len(dataMain.Data) == 0 {
output.RenderError(noDataError, outputOptions)
os.Exit(1)
output.RenderInfo("No ssh-keys for any users", outputOptions)
os.Exit(0)
}
output.RenderOutput(dataMain, outputOptions)

Expand Down
10 changes: 5 additions & 5 deletions pkg/api/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (api *Interface) AddBackup(backup AddBackup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func (api *Interface) DeleteBackup(backup DeleteBackup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (api *Interface) UpdateRestore(update UpdateRestore) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func (api *Interface) GetAllEnvironmentBackups() ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (api *Interface) GetEnvironmentBackups(backups EnvironmentBackups) ([]byte,
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
10 changes: 5 additions & 5 deletions pkg/api/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (api *Interface) GetEnvironmentByName(environment EnvironmentByName, fragme
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (api *Interface) AddOrUpdateEnvironment(environment AddUpdateEnvironment) (
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (api *Interface) UpdateEnvironment(environment UpdateEnvironment) ([]byte,
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (api *Interface) DeleteEnvironment(environment DeleteEnvironment) ([]byte,
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -194,7 +194,7 @@ func (api *Interface) SetEnvironmentServices(environment SetEnvironmentServices)
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
16 changes: 8 additions & 8 deletions pkg/api/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (api *Interface) AddGroup(group AddGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func (api *Interface) AddGroupWithParent(group AddGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (api *Interface) UpdateGroup(group UpdateGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (api *Interface) DeleteGroup(group AddGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func (api *Interface) AddUserToGroup(user AddUserToGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (api *Interface) AddGroupToProject(group ProjectToGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -238,7 +238,7 @@ func (api *Interface) RemoveGroupFromProject(group ProjectToGroup) ([]byte, erro
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func (api *Interface) RemoveUserFromGroup(user UserGroup) ([]byte, error) {
debugResponse(jsonBytes)
}
if string(jsonBytes) == "null" {
return []byte(""), errors.New("graphql: returned null")
return []byte(""), errors.New("GraphQL API returned a null response, the requested resource may not exist, or there was an error. Use `--debug` to check what was returned")
}
return jsonBytes, nil
}
Loading