Skip to content

Commit 921ad6e

Browse files
author
Jon Poole
committed
Improve some things around how errors are logged when parsing a file
1 parent 7595575 commit 921ad6e

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

compile/compile.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package compile
99
// FIXME kill ast.Identifier and turn into string?
1010

1111
import (
12+
"bytes"
1213
"fmt"
1314
"log"
1415
"strings"
@@ -107,7 +108,7 @@ func init() {
107108
// in addition to any features explicitly specified.
108109
func Compile(src, srcDesc string, mode py.CompileMode, futureFlags int, dont_inherit bool) (*py.Code, error) {
109110
// Parse Ast
110-
Ast, err := parser.ParseString(src, mode)
111+
Ast, err := parser.Parse(bytes.NewBufferString(src), srcDesc, mode)
111112
if err != nil {
112113
return nil, err
113114
}

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func xmain(args []string) {
7878
_, err := py.RunFile(ctx, args[0], py.CompileOpts{}, nil)
7979
if err != nil {
8080
py.TracebackDump(err)
81-
log.Fatal(err)
81+
os.Exit(1)
8282
}
8383
}
8484
}

parser/lexer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ func (x *yyLex) SyntaxErrorf(format string, a ...interface{}) {
916916
func (x *yyLex) ErrorReturn() error {
917917
if x.error {
918918
if x.errorString == "" {
919-
if x.eof && x.interactive {
919+
if x.eof {
920920
x.errorString = "unexpected EOF while parsing"
921921
} else {
922922
x.errorString = "invalid syntax"

py/traceback.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func TracebackDump(err interface{}) {
6464
case *ExceptionInfo:
6565
e.TracebackDump(os.Stderr)
6666
case *Exception:
67-
fmt.Fprintf(os.Stderr, "Exception %#v\n", e)
67+
fmt.Fprintf(os.Stderr, "Exception %v\n", e)
6868
fmt.Fprintf(os.Stderr, "-- No traceback available --\n")
6969
default:
70-
fmt.Fprintf(os.Stderr, "Error %#v\n", err)
70+
fmt.Fprintf(os.Stderr, "Error %v\n", err)
7171
fmt.Fprintf(os.Stderr, "-- No traceback available --\n")
7272
}
7373
}

0 commit comments

Comments
 (0)