spec icon indicating copy to clipboard operation
spec copied to clipboard

Stack error messages in Score implementation CLIs

Open sujaya-sys opened this issue 2 years ago • 11 comments

Currently, if I write a bad flag - the CLI will complain about that, so I’ll fix it. Then I’ll rerun my command and the CLI will complain about the next error message. Is it possible to stack error messages? For example: Error: unknown flags: --org, --env, --deploy.

sujaya-sys avatar Oct 31 '22 19:10 sujaya-sys

Hi, Can I work on this?

enraiha0307 avatar Jan 11 '23 08:01 enraiha0307

@enraiha0307 you're welcome to! This issue exists for both score-compose and score-helm - Please let me know if there's additional engineering input we can provide to support you with solving this task. You can drop in your questions in this thread.

sujaya-sys avatar Jan 11 '23 08:01 sujaya-sys

@sujaya-sys Thanks, Will let you know.

enraiha0307 avatar Jan 11 '23 08:01 enraiha0307

Hello everyone, I was trying to run e2e tests on the main branch but got some failures. I have followed the readme instructions but while running go run ./cli I got this message.

❯ go run ./cli
go: no packages loaded from ./cli

And after running robot e2e-tests

------------------------------------------------------------------------------
E2E-Tests.Score-Compose-Examples :: Verification for examples of s... | FAIL |
4 tests, 0 passed, 4 failed
==============================================================================
E2E-Tests                                                             | FAIL |
14 tests, 10 passed, 4 failed
==============================================================================

Am I doing something wrong here? Please help. I have attached the e2e test report zip below. report.zip

enraiha0307 avatar Jan 31 '23 11:01 enraiha0307

@Nilsty any chance you could take a look at the above described issue? Thanks a lot!

sujaya-sys avatar Jan 31 '23 12:01 sujaya-sys

Hi @enraiha0307 , The go run command to run score-compose would be go run ./cmd/score-compose. I updated it now in the readme. Looking at your test report it seems to be failing as you miss docker compose locally. After installing the compose plugin your test should run fine.

Nilsty avatar Jan 31 '23 13:01 Nilsty

okay @Nilsty, Thanks for the help. I'll try this.

enraiha0307 avatar Jan 31 '23 13:01 enraiha0307

Hi all, I could not contribute much in the past month due to a medical emergency. For this error message, I found that it is being printed and returned by an internal function used inside Execute(). I searched through the cobra package but there was no function or array which would return command line args, Just so that we could parse it ourselves and print the stacked error message. There was one Property called DisableFlagParsing: true, used inside the Command struct to disable the parsing and we could write our own small flag parsing function. I tried it and was able to print the desired error stack message.

docker run -it score-compose:latest run -lfjnb
Usage:
  score-compose run [flags]

Flags:
      --build string       Replaces 'image' name with compose 'build' instruction
      --env-file string    Location to store sample .env file
  -f, --file string        Source SCORE file (default "./score.yaml")
  -h, --help               help for run
  -o, --output string      Output file
      --overrides string   Overrides SCORE file (default "./overrides.score.yaml")
      --verbose            Enable diagnostic messages (written to STDERR)

**unknown flags l, j, n, b%**     
  

But then after testing for other commands I found that scoreFileDefault and overridesFileDefault were not getting populated. Therefore using DisableParsing will mean writing the whole parsing logic by ourselves.

Another possible solution is to create an issue in cobra and add some functionality for returning this stacked error messages or atleast command line args. And then use it in our code.

So I want your insights/suggestions on this.

enraiha0307 avatar Mar 08 '23 12:03 enraiha0307

Hi, I have created a Parser function that iterates through all commands and their respective flags and stores the invalid flags/commands in a slice. It is invoked before command.Execute() in cmd/main.go. If there are invalid flags/commands, it prints the error stack along with help instructions and ends the program. Only if there are no invalid flags/commands, the command.Execute() will run. I am working on robot-testcases now. Let me know if its okay/ needs any other changes.

# Sample output:
 ~/ go run ./cmd/score-compose  -levwe
Error: Unknown command/flags: l, e, w, 
Use "score-compose --help" for more information.

enraiha0307 avatar Apr 22 '23 12:04 enraiha0307

Hi @sujaya-sys, @Nilsty I've run the e2e-tests and got a green report. I've also created a pull request, please review it when you've time. https://github.com/score-spec/score-compose/pull/32 e2e-reports.zip

enraiha0307 avatar Apr 24 '23 13:04 enraiha0307

Thanks a lot for your contribution @enraiha0307 - I'll make sure we'll get your PR https://github.com/score-spec/score-compose/pull/32 reviewed! 🙂

sujaya-sys avatar Apr 27 '23 12:04 sujaya-sys

I'm going to close this and suggest that this is down to individual implementations to implement as they choose. Feel free to continue with the score-compose specific PR.

👍

astromechza avatar May 29 '24 21:05 astromechza