瀏覽代碼

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

Mislav Marohnić 9 年之前
父節點
當前提交
5fd46c34b4
共有 2 個文件被更改,包括 8 次插入0 次删除
  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())