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

Panic while a program is runing as windows system service #76

Open
chenjie4255 opened this issue Feb 8, 2025 · 4 comments
Open

Panic while a program is runing as windows system service #76

chenjie4255 opened this issue Feb 8, 2025 · 4 comments

Comments

@chenjie4255
Copy link

panic: nil passed instead of *os.File to NewColorable()

goroutine 1 [running]:
github.com/mattn/go-colorable.NewColorable(0x0)
	C:/Users/chen/go/pkg/mod/github.com/mattn/[email protected]/colorable_windows.go:104 +0x3d6
github.com/mattn/go-colorable.NewColorableStdout()
	C:/Users/chen/go/pkg/mod/github.com/mattn/[email protected]/colorable_windows.go:122 +0x25
github.com/fatih/color.init()
	C:/Users/chen/go/pkg/mod/github.com/fatih/[email protected]/color.go:27 +0x12d

It looks like the os.Stdout may be nil in this case.

Image

It would be better if we could have a method to get around this panic.

@mattn
Copy link
Owner

mattn commented Feb 8, 2025

NewColorable does not accept nil. On Windows NT Service, os.Stdout always be nil. Can you avoid to use fatih/color in your code?

@mattn
Copy link
Owner

mattn commented Feb 8, 2025

Or, you can avoid this with below

color.Output = io.Discard
color.Error = io.Discard

@chenjie4255
Copy link
Author

chenjie4255 commented Feb 8, 2025

NewColorable does not accept nil. On Windows NT Service, os.Stdout always be nil. Can you avoid to use fatih/color in your code?

make sense, I will try to reach out to the faith/color project to see what could be done on their side.

Or, you can avoid this with below

color.Output = io.Discard
color.Error = io.Discard

Thanks for your tips. but where should I put those codes on? since it happened on the go init procedure.

@mattn
Copy link
Owner

mattn commented Feb 8, 2025

It should be at init func.

func init() {
    if os.Stdout == nil {
        color.Output = io.Discard
        color.Error = io.Discard
    }
}

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

No branches or pull requests

2 participants