From b7f4307761c61d2d3f563c37b0c9ad0e64899d9f Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 19 Feb 2021 12:42:57 +0700 Subject: [PATCH] cmd/compile: graceful handle error in noder LoadPackage When syntax.Parse returns error, noder.file will be nil. Currently, we continue accessing it regardlessly and depend on gc.hidePanic to hide the panic from user. Instead, we should gracefully handle the error in LoadPackage, then exit earlier if any error occurred. Updates #43311 Change-Id: I0a108ef360bd4f0cc9f481071b8967355e1513af Reviewed-on: https://go-review.googlesource.com/c/go/+/294030 Trust: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/noder/noder.go | 3 +++ test/fixedbugs/bug050.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index d692bf97aaf..8c456e4561e 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -68,6 +68,9 @@ func LoadPackage(filenames []string) { for e := range p.err { p.errorAt(e.Pos, "%s", e.Msg) } + if p.file == nil { + base.ErrorExit() + } lines += p.file.EOF.Line() } base.Timer.AddEvent(int64(lines), "lines") diff --git a/test/fixedbugs/bug050.go b/test/fixedbugs/bug050.go index aba68b1dcbb..1e299ed99a8 100644 --- a/test/fixedbugs/bug050.go +++ b/test/fixedbugs/bug050.go @@ -1,4 +1,4 @@ -// errorcheck +// errorcheck -d=panic // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style