Skip to content

Commit

Permalink
cmd/go: allow go fmt to complete when embedded file is missing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
iwdgo authored and Jay Conrod committed Jan 19, 2021
1 parent 0575e35 commit 824f2d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cmd/go/internal/fmtcmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions src/cmd/go/testdata/script/embed_fmt.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 824f2d6

Please sign in to comment.