box-cli-maker icon indicating copy to clipboard operation
box-cli-maker copied to clipboard

ASoC: Remove `errorMsg` and replace it with `err` type

Open Delta456 opened this issue 2 years ago • 5 comments

There is a function errorMsg which prints to the stderr stream when there is an error. In production open must never print to stderr because it may conflict with other things present in the product, and can cause debugging to become very hard.

For example, the below code can be turned into:

// roundOffTitleColor rounds off 24 bit Color to the terminals maximum color capacity for Title.
func (b Box) roundOffTitleColor(col color.RGBColor, title string) string {
	switch detectTerminalColor() {
	case terminfo.ColorLevelNone:
		errorMsg("[warning]: terminal does not support colors, using no effects")
		return title
	case terminfo.ColorLevelMillions:
		return col.Sprint(title)
	default:
		return col.C256().Sprint(title)
	}
}
// roundOffTitleColor rounds off 24 bit Color to the terminals maximum color capacity for Title.
func (b Box) roundOffTitleColor(col color.RGBColor, title string) (string, err) {
	switch detectTerminalColor() {
	case terminfo.ColorLevelNone:
		return title, errors.New("terminal does not support colors")
	case terminfo.ColorLevelMillions:
		return col.Sprint(title), nil
	default:
		return col.C256().Sprint(title), nil
	}
}

then, do the changes as per the need.

This is a very breaking change so this has to be some with cautious.

Delta456 avatar Aug 21 '23 16:08 Delta456

Hey @Delta456, Can I work on this?

AniketNS avatar Nov 16 '23 05:11 AniketNS

Hey @Delta456, Can I work on this?

Sure

Delta456 avatar Nov 16 '23 05:11 Delta456

Hye @Delta456, I've created the PR, will you please check and tell me if this is correct or not?

AniketNS avatar Nov 16 '23 08:11 AniketNS