1
0
mirror of https://github.com/golang/go synced 2024-11-22 18:54:44 -07:00

cmd/go: allow go fmt to complete when embedded file is missing

Fixes #43273

Change-Id: I75fe2e608cb43c048e3c2a22fe7fbb6eb779504a
Reviewed-on: https://go-review.googlesource.com/c/go/+/280452
Trust: Jay Conrod <jayconrod@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Constantin Konstantinidis 2021-01-15 17:05:29 +01:00 committed by Jay Conrod
parent 0575e35e50
commit 824f2d635c
2 changed files with 24 additions and 1 deletions

View File

@ -75,7 +75,8 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
}
if pkg.Error != nil {
var nogo *load.NoGoError
if errors.As(pkg.Error, &nogo) && len(pkg.InternalAllGoFiles()) > 0 {
var embed *load.EmbedError
if (errors.As(pkg.Error, &nogo) || errors.As(pkg.Error, &embed)) && len(pkg.InternalAllGoFiles()) > 0 {
// Skip this error, as we will format
// all files regardless.
} else {

View File

@ -0,0 +1,22 @@
# go fmt ignores file not found
go fmt xnofmt.go
cmp xnofmt.go xfmt.ref
! go build xnofmt.go
stderr 'xnofmt.go:5:12: pattern missing.txt: no matching files found'
-- xnofmt.go --
package p
import "embed"
//go:embed missing.txt
var X embed.FS
-- xfmt.ref --
package p
import "embed"
//go:embed missing.txt
var X embed.FS
-- go.mod --
module m