Skip to content

Commit 824f2d6

Browse files
iwdgoJay Conrod
authored and
Jay Conrod
committed
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 <[email protected]> Trust: Bryan C. Mills <[email protected]> Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 0575e35 commit 824f2d6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/cmd/go/internal/fmtcmd/fmt.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
7575
}
7676
if pkg.Error != nil {
7777
var nogo *load.NoGoError
78-
if errors.As(pkg.Error, &nogo) && len(pkg.InternalAllGoFiles()) > 0 {
78+
var embed *load.EmbedError
79+
if (errors.As(pkg.Error, &nogo) || errors.As(pkg.Error, &embed)) && len(pkg.InternalAllGoFiles()) > 0 {
7980
// Skip this error, as we will format
8081
// all files regardless.
8182
} else {
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# go fmt ignores file not found
2+
go fmt xnofmt.go
3+
cmp xnofmt.go xfmt.ref
4+
! go build xnofmt.go
5+
stderr 'xnofmt.go:5:12: pattern missing.txt: no matching files found'
6+
7+
-- xnofmt.go --
8+
package p
9+
10+
import "embed"
11+
12+
//go:embed missing.txt
13+
var X embed.FS
14+
-- xfmt.ref --
15+
package p
16+
17+
import "embed"
18+
19+
//go:embed missing.txt
20+
var X embed.FS
21+
-- go.mod --
22+
module m

0 commit comments

Comments
 (0)