Skip to content

Commit 2943542

Browse files
authored
Merge pull request #50 from ReconfigureIO/bugfix/error-on-parse-error
Use Perish() on parse errors.
2 parents f132dd3 + d28ff42 commit 2943542

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cmd/goblin/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func main() {
3636
} else if *fileFlag != "" {
3737
file, err := os.Open(*fileFlag)
3838
if err != nil {
39-
panic(err)
39+
goblin.Perish(goblin.TOPLEVEL_POSITION, "path_error", err.Error())
4040
}
4141
info, err := file.Stat()
4242
if err != nil {
43-
panic(err)
43+
goblin.Perish(goblin.TOPLEVEL_POSITION, "path_error", err.Error())
4444
}
4545

4646
size := info.Size()
@@ -50,7 +50,7 @@ func main() {
5050

5151
f, err := parser.ParseFile(fset, *fileFlag, nil, parser.ParseComments)
5252
if err != nil {
53-
panic(err)
53+
goblin.Perish(goblin.INVALID_POSITION, "positionless_syntax_error", err.Error())
5454
}
5555

5656
if *builtinDumpFlag {

goblin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Perish(pos token.Position, typ string, reason string) {
3939
"position": DumpPosition(pos),
4040
},
4141
})
42-
os.Stdout.Write(res)
42+
os.Stderr.Write(res)
4343
}
4444
os.Exit(1)
4545
}

0 commit comments

Comments
 (0)