From 824f2d635ca96a7bded6ed039f8a9c0f06ee1443 Mon Sep 17 00:00:00 2001 From: Constantin Konstantinidis Date: Fri, 15 Jan 2021 17:05:29 +0100 Subject: [PATCH] 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 Trust: Bryan C. Mills Run-TryBot: Jay Conrod TryBot-Result: Go Bot Reviewed-by: Jay Conrod --- src/cmd/go/internal/fmtcmd/fmt.go | 3 ++- src/cmd/go/testdata/script/embed_fmt.txt | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/embed_fmt.txt diff --git a/src/cmd/go/internal/fmtcmd/fmt.go b/src/cmd/go/internal/fmtcmd/fmt.go index b0c1c59b40..6b98f0ccd3 100644 --- a/src/cmd/go/internal/fmtcmd/fmt.go +++ b/src/cmd/go/internal/fmtcmd/fmt.go @@ -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 { diff --git a/src/cmd/go/testdata/script/embed_fmt.txt b/src/cmd/go/testdata/script/embed_fmt.txt new file mode 100644 index 0000000000..8a16afea8a --- /dev/null +++ b/src/cmd/go/testdata/script/embed_fmt.txt @@ -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