Skip to content

embed: magic go embed import requirement is unnecessarily cryptic #73955

Closed
@wyattscarpenter

Description

@wyattscarpenter

Go version

go version go1.24.3 windows/amd64, which I just downloaded today from your website https://go.dev/dl/

Output of go env in your module/workspace:

irrelevant

What did you do?

//go:embed README.md
var readme string

gets the error message go:embed only allowed in Go files that import "embed"

Adding import "embed" or import ( "embed" ) to the file gets you the error "embed" imported and not used. Instead, you have to import _ "embed". So that's what the error message should tell you to do. (It also works if you use embed, the real package, presumably, but the user isn't doing that or the user wouldn't have seen the first error message in the first place!)

What did you see happen?

Cryptic error messages that won't make sense to anyone not already intimately familiar with go's magic import requirement for //go:embed.

What did you expect to see?

Perhaps extend the error message to be go:embed only allowed in Go files that import "embed"; try import _ "embed". Or count the hot comment as a usage for the purposes of the unused import logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions