Skip to content

ASoC: Remove errorMsg and replace it with err type #36

@Delta456

Description

@Delta456

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions