Skip to content

Commit d32cddf

Browse files
dmullisdmullis
authored andcommitted
Better diagnostic upon abort for TAB char in input
1 parent 029f2d5 commit d32cddf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

canvas.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package goat
22

33
import (
44
"bufio"
5+
"log"
56
"io"
7+
"os"
68
)
79

810
type (
@@ -156,14 +158,19 @@ func NewCanvas(in io.Reader) (c Canvas) {
156158
// https://go.dev/ref/spec#For_statements
157159
// But yet, counterintuitively, type of lineStr[_index_] is 'byte'.
158160
// https://go.dev/ref/spec#String_types
159-
// XXXX Refactor to use []rune from above.
160161
for _, r := range lineStr {
161162
//if r > 255 {
162163
// fmt.Printf("linestr=\"%s\"\n", lineStr)
163164
// fmt.Printf("r == 0x%x\n", r)
164165
//}
165166
if r == ' ' {
166-
panic("TAB character found on input")
167+
file, isFile := in.(*os.File)
168+
fileName := "unknown"
169+
if isFile {
170+
fileName = file.Name()
171+
}
172+
log.Panicf("\n\tFound TAB in %s, row %d, column %d\n",
173+
fileName, height+1, w)
167174
}
168175
i := Index{w, height}
169176
c.data[i] = r

0 commit comments

Comments
 (0)