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

Exit with error message to stderr and non-zero status code #980

Open
FrontSide opened this issue Apr 18, 2024 · 1 comment
Open

Exit with error message to stderr and non-zero status code #980

FrontSide opened this issue Apr 18, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@FrontSide
Copy link

Is your feature request related to a problem? Please describe.
As far as I can see there is no (standardised) way to make a controlled exit of the program with an error message and exit code

Describe the solution you'd like
Take you http example, for instance. In the case that the server responds with an error HTTP status code, you are currently just printing the error, but the program keeps running and all I can do is exit with "q, ctrl+c".
Really what I would expect as a user is probably to receive an error message (maybe even in a bold red font) to stderr (not stdout) and for the program to stop with a non-0 error code.
Is there a recommended way for doing this at the moment?

Describe alternatives you've considered
To achieve the above at the moment, what I'd probably do is, format the message myself to look more like an error and simply exit the program in my View() function with log.Fatalf()

Additional context
n/a

@FrontSide FrontSide added the enhancement New feature or request label Apr 18, 2024
@ajayd-san
Copy link

I know it's late but what I usually like to do is to have a field of type error in my Model instance and I check it once the model quits.

if m, err := tea.NewProgram(m, tea.WithAltScreen()).Run(); err != nil {
   fmt.Println("Error running program:", err)
   return err
}

if m.err != nil {
	log.Fatal(m.err.Error())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants