Why would Franklin fail because "`@sprintf` not defined"?

This is while building GMT docs, but both GMT and the GMT docs repo have Printf as a dependency. And locally the build works fine.
This error in particular raised when running this case but there are several other examples.

Hello @joa-quim can you share the Project.toml file that you use in the website folder (or point to a repo)? Separately, in the github action workflow file you can try to make the installation of Printf explicit (with Pkg.add) prior to the Franklin lines.

Edit found the repo, I can’t directly see the issue. For debugging purposes I’d suggest having a separate repo with a single page where we can investigate a bit, e.g. seeing if using a qualified Printf.@sprintf helps. If I get some time during the weekend I’ll give it a shot.

Thanks for looking at this (as usual). A little correction. Locally the script runs fine but when I build the full docs I get the same error. Tried the qualified Printf.@sprintf but got essential the same error though this time it says.

LoadError: UndefVarError: `Printf` not defined

though the script starts with

using GMT, Printf

Sorry, took me a bit of time to have a look at this

using GMT, Printf
@sprintf "this is a %s %15.1f" "test" 34.567

works fine for me locally, from your last message it seems that this is the same for you.

The full one (from your link, copied in details below) doesn’t, I get

Something went wrong when calling the module. GMT error number = 72

(at one earlier point I had gotten

Bad argument type (Tuple{Matrix{Float64}, String}) to option C

this was without any changes to your code, am not going to dig deeper here)

this is what I used, copy pasted from the link you posted

using GMT, Printf

pratt = [-142.65 56.25 400]

# First generate gravity image w/ shading, label Pratt, and draw a circle
# of radius = 200 km centered on Pratt.
grav_cpt = makecpt(color=:rainbow, range=(-60,60));
grdimage("@AK_gulf_grav.nc", shade=:default, frame=(annot=2,ticks=1), proj=:merc, figsize=14, xshift=3.8, yshift=14.9)
coast!(region="@AK_gulf_grav.nc", land=:gray, shore=:thinnest)
colorbar!(pos=(anchor=:BC, offset=(0,1)), xaxis=(annot=20, ticks=10), ylabel="mGal")
text!(text_record(pratt, "Pratt"), font=(12,"Helvetica-Bold"), justify=:LB, offset="8p")
plot!(pratt, marker="E-", markerline=:thinnest)

# Then draw 10 mGal contours and overlay 50 mGal contour in green
grdcontour!("@AK_gulf_grav.nc", cont=20, frame=(axes=:WSEn, annot=2, ticks=1), yshift=-12.3)
# Save 50 mGal contours to individual files, then plot them
grdcontour!("@AK_gulf_grav.nc", cont=10, range=(49,51), dump="sm_%c.txt")
plot!("sm_C.txt", lw=:thin, lc=:green)
coast!(land=:gray, shore=:thinnest)
plot!(pratt, marker="E-", markerline=:thinnest)

# Now determine centers of each enclosed seamount > 50 mGal but only plot
# the ones within 200 km of Pratt seamount.

# First determine mean location of each closed contour and add it to the file centers.txt
centers = gmtspatial("sm_C.txt", length=true, colinfo=:g)

# Only plot the ones within 200 km
t = gmtselect(centers, C=(pratt,"200k"), colinfo=:g)
plot!(t, marker=:Circle, ms=0.2, mc=:red, MarkerLine=:thinnest)
plot!(pratt, marker=:Triangle, ms=0.25, fill=:yellow, MarkerLine=:thinnest)

# Then report the volume and area of these seamounts only
# by masking out data outside the 200 km-radius circle
# and then evaluate area/volume for the 50 mGal contour

Gmask = gmt(string("grdmath -R@AK_gulf_grav.nc ", pratt[1], " ", pratt[2], " SDIST ="))
Gmask = grdclip(Gmask, above=(200, NaN), below=(200, 1))
Gtmp = gmt("grdmath @AK_gulf_grav.nc ? MUL =", Gmask);
av   = grdvolume(Gtmp, cont=50, unit=:k);

T = mat2ds([@sprintf("Volumes: %d mGal\\264km@+2@+", av.data[3])
    @sprintf("Areas: %.2f km@+2@+", av.data[2])], hdr="> -149 52.5 14p 2.6i j")

text!(T, paragraph=true, fill=:white, pen=:thin, offset=0.75, font=(14,"Helvetica-Bold"),
      justify=:LB, clearance=0.25, show=true)

Remotely stuff works fine, no pkg issue, the first cell works fine (so there’s no GMT/Printf weird issue) but same code error for the second cell with bad argument type (Test printf)

Btw, to debug problems like this, it’s useful to have a separate dummy repo (like this one) where you have a single page and only one code cell so that you can identify more specifically where the problem comes from. When you’re building a full website, the error messages can be confusing and misleading. In this specific case, I’d investigate the error message, the package error seems to me like a red-herring.

Separately, whenever there’s a disconnect between local and remote, it’s usually an environment setup issue where your environment is improperly setup but you don’t realise it because Julia figures out it can use your general environment as a fallback; on GHA however, there’s no fallback. Again a dummy repo can help you figure that out.

I hope this helps a bit!