Ver Fonte

Panic with explicit reason if nil was passed to NewColorable()

Mislav Marohnić há 9 anos atrás
pai
commit
5fd46c34b4
2 ficheiros alterados com 8 adições e 0 exclusões
  1. 4 0
      colorable_others.go
  2. 4 0
      colorable_windows.go

+ 4 - 0
colorable_others.go

@@ -8,6 +8,10 @@ import (
 )
 
 func NewColorable(file *os.File) io.Writer {
+	if file == nil {
+		panic("nil passed instead of *os.File to NewColorable()")
+	}
+
 	return file
 }
 

+ 4 - 0
colorable_windows.go

@@ -69,6 +69,10 @@ type Writer struct {
 }
 
 func NewColorable(file *os.File) io.Writer {
+	if file == nil {
+		panic("nil passed instead of *os.File to NewColorable()")
+	}
+
 	if isatty.IsTerminal(file.Fd()) {
 		var csbi consoleScreenBufferInfo
 		handle := syscall.Handle(file.Fd())