spacelift-io / spacectl

Spacelift client and CLI
MIT License
131 stars 35 forks source link

Improve user facing error massage when the stack is not found #182

Closed mwasilew2 closed 1 year ago

mwasilew2 commented 1 year ago

closes: https://app.clickup.com/t/862k09kgc

Includes in the error message a hint about how to list available stacks.

Note: The GraphQL API doesn't return errors that can be typed. The string parsing is a dirty hack, if anyone knows of a better way to approach it let me know.

Clickup-user commented 1 year ago

Task linked: CU-862k09kgc Add suggestions when spacectl does not find an entity

tomasmik commented 1 year ago

We have this function called getStackID which is called every time you do anything with a command which interacts with stacks: https://github.com/spacelift-io/spacectl/blob/main/internal/cmd/stack/stack_selector.go#L19

Because this is called every time we parse the provided --id I was thinking maybe we could actually just look up and check if the provided stack actually exists in spacelift instead of just returning the provided name?

    if cliCtx.IsSet(flagStackID.Name) {
        return cliCtx.String(flagStackID.Name), nil
    }

Would you mind look in to that and seeing if that actually works?

mwasilew2 commented 1 year ago

We have this function called getStackID which is called every time you do anything with a command which interacts with stacks: https://github.com/spacelift-io/spacectl/blob/main/internal/cmd/stack/stack_selector.go#L19

Because this is called every time we parse the provided --id I was thinking maybe we could actually just look up and check if the provided stack actually exists in spacelift instead of just returning the provided name?

  if cliCtx.IsSet(flagStackID.Name) {
      return cliCtx.String(flagStackID.Name), nil
  }

Would you mind look in to that and seeing if that actually works?

You're right, it makes more sense to check for stack presence when we're extracting the stack id. The additional benefit of this is that this function is used in other places so we get nice error handling in those places as well.

@tomasmik let me know what you think of this approach