mirror of
https://github.com/golang/go
synced 2024-11-26 09:48:14 -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:
parent
0575e35e50
commit
824f2d635c
@ -75,7 +75,8 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
|
|||||||
}
|
}
|
||||||
if pkg.Error != nil {
|
if pkg.Error != nil {
|
||||||
var nogo *load.NoGoError
|
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
|
// Skip this error, as we will format
|
||||||
// all files regardless.
|
// all files regardless.
|
||||||
} else {
|
} else {
|
||||||
|
22
src/cmd/go/testdata/script/embed_fmt.txt
vendored
Normal file
22
src/cmd/go/testdata/script/embed_fmt.txt
vendored
Normal 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
|
Loading…
Reference in New Issue
Block a user