Gotcha: referencing symlinks with go:embed result in irregular file errors

Featured image for sharing metadata for article

Early in 2024, I hit an issue with Go not allowing me to use go:embed.

(Aside: this is one of those posts that has been on the backburner and I'm finally getting around to it given I had a few minutes spare, and I want to test some new functionality in my blog-to-LinkedIn syndication.)

I can't remember the full details for what I was exactly doing, but I remember having a set of files such as:

% ls -al
total 20
drwxr-xr-x 2 jamie jamie  4096 Sep 10 15:00 .
drwx------ 3 jamie jamie  4096 Sep 10 14:59 ..
-rw-r--r-- 1 jamie jamie 12262 Sep 10 15:00 favicon.png
lrwxrwxrwx 1 jamie jamie    52 Sep 10 14:59 profile.png -> /home/jamie/workspaces/jvt.me/static/img/profile.png

With this, I was then using the excellent go:embed functionality, like so:

package main

import (
	_ "embed"
	"fmt"
)


}

//go:embed static/*.png
var images embed.FS

// ...

This was giving me a rather obtuse error:

main.go:11:12: pattern static/*.png: cannot embed irregular file static/profile.png

Upon further digging, it was down to the fact that I had many files that were fine, and one of which was a symlink (aka symbolic link), which was tripping up Go.

It turns out it has been fixed upstream but only if opting in to this behaviour with i.e.:

env GODEBUG=embedfollowsymlinks=1 go build

This only appears in Go 1.25+.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #go.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.