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

[deploy branch command] Exit code returns 0, should return > 0 for errors #189

Open
bryangruneberg opened this issue Jul 7, 2021 · 5 comments
Labels
bug Something isn't working easy lagoon-upstream Issue needs to be raised in Lagoon

Comments

@bryangruneberg
Copy link

Describe the bug
Exit code returns 0, should return > 0 for errors

To Reproduce
cool-project is a dummy project name

$ lagoon deploy branch -p cool-project -b master
Error: UnknownActiveSystem: Unknown active system 'lagoon_kubernetesBuildDeploy' for task 'deploy' in for project cool-project
$ echo $?
0

Expected behavior

$ lagoon --force deploy branch -p cool-project -b master
Error: UnknownActiveSystem: Unknown active system 'lagoon_kubernetesBuildDeploy' for task 'deploy' in for project cool-project
$ echo $?
255

Exit codes are a number between 0 and 255

@shreddedbacon shreddedbacon added bug Something isn't working easy labels Jul 7, 2021
@janmashat
Copy link

I believe this failed deploy also returned exit code 0

10:08:31  + lagoon --force deploy branch -p cool-project -b test
10:08:31  Deploying cool-project test
10:08:32  Result: [33mError: SyntaxError: Invalid regular expression: /*/: Nothing to repeat[0m

@shreddedbacon
Copy link
Member

shreddedbacon commented Jul 9, 2021

Yeah, there is no other exit code except 0 for this command. I'll try and get a fix and release in the next few days. The Lagoon API only responds with a string, unless there is an actual error within the API, so we would need to do a string check for the existence of Error in the CLI. But we should also probably make sure the Lagoon API responds with an actual error if there is an error.

EDIT: More clarification

@shreddedbacon shreddedbacon added the lagoon-upstream Issue needs to be raised in Lagoon label Jul 9, 2021
@shreddedbacon
Copy link
Member

Checking this functionality in a local development Lagoon, the response from the graphql mutation to trigger a deployment results in this

# first update a project to use an invalid build system
mutation updateProject {
  updateProject(input: {
    id: 32, 
    patch: {
      activeSystemsDeploy: "lagoon_kubernetesBuildDeploy"
    }
  }) {
    standbyRoutes
  }
}
# then deploy the latest of an environment within that project
mutation deployLatest {
    deployEnvironmentLatest(input: {
      environment: {
        id:14
      }
    }
  )
}

See that the error is just a string result.

{
  "data": {
    "deployEnvironmentLatest": "Error: Unknown active system 'lagoon_kubernetesBuildDeploy' for task 'deploy' in for project ci-features-control-k8s"
  }
}

If we run the same against a non existing, or id that we have no authority to act on, we get an actual error from the API like so

{
  "errors": [
    {
      "message": "Unauthorized",
      "locations": [
        {
          "line": 1412,
          "column": 5
        }
      ],
      "path": [
        "deployEnvironmentLatest"
      ]
    }
  ],
  "data": {
    "deployEnvironmentLatest": null
  }
}

@shreddedbacon
Copy link
Member

The same if we run the same command using the CLI

$ lagoon -l local deploy branch -p example-com -b no-permission --force
Error: graphql: Unauthorized
Usage:
  lagoon deploy branch [flags]

Aliases:
  branch, b

Flags:
  -b, --branch string   Branch name to deploy
  -h, --help            help for branch

Global Flags:
      --config-file string   Path to the config file to use (must be *.yml or *.yaml)
      --debug                Enable debugging output (if supported)
  -e, --environment string   Specify an environment to use
      --force                Force yes on prompts (if supported)
  -l, --lagoon string        The Lagoon instance to interact with
      --no-header            No header on table (if supported)
      --output-csv           Output as CSV (if supported)
      --output-json          Output as JSON (if supported)
      --pretty               Make JSON pretty (if supported)
  -p, --project string       Specify a project to use
      --skip-update-check    Skip checking for updates
  -i, --ssh-key string       Specify path to a specific SSH key to use for lagoon authentication

Error: graphql: Unauthorized
$ echo $?
1

@shreddedbacon
Copy link
Member

I've put a PR in that fixes this, but we really should try and fix this in the Lagoon API properly rather than this fix in the CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working easy lagoon-upstream Issue needs to be raised in Lagoon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants