terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
16.72k stars 419 forks source link

Can't render images due to bug in d2 source #1524

Open mark-summerfield opened 1 year ago

mark-summerfield commented 1 year ago

I'm using Go 1.20.7 on Debian 11. I am using the example https://github.com/terrastruct/d2/tree/master/docs/examples/lib/1-d2lib Here's the output when I try go run .:

/home/mark/opt/gows/pkg/mod/oss.terrastruct.com/d2@v0.6.0/lib/log/log.go:52:28: cannot use fields (variable of type []slog.Field) as []any value in argument to from(ctx).Debug
/home/mark/opt/gows/pkg/mod/oss.terrastruct.com/d2@v0.6.0/lib/log/log.go:57:27: cannot use fields (variable of type []slog.Field) as []any value in argument to from(ctx).Info
/home/mark/opt/gows/pkg/mod/oss.terrastruct.com/d2@v0.6.0/lib/log/log.go:62:27: cannot use fields (variable of type []slog.Field) as []any value in argument to from(ctx).Warn
/home/mark/opt/gows/pkg/mod/oss.terrastruct.com/d2@v0.6.0/lib/log/log.go:67:28: cannot use fields (variable of type []slog.Field) as []any value in argument to from(ctx).Error
/home/mark/opt/gows/pkg/mod/oss.terrastruct.com/d2@v0.6.0/lib/log/log.go:72:31: cannot use fields (variable of type []slog.Field) as []any value in argument to from(ctx).Critical
/home/mark/opt/gows/pkg/mod/oss.terrastruct.com/d2@v0.6.0/lib/log/log.go:77:28: cannot use fields (variable of type []slog.Field) as []any value in argument to from(ctx).Fatal
mark-summerfield commented 1 year ago

I tried adding these lines after main() {:

    logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
    slog.SetDefault(logger)

but they didn't help.

But if I comment out the bodies of the functions Debug, Info, Warn, Error, Critical, Fatal in file oss.terrastruct.com/d2@v0.6.0/lib/log/log.go, then everything works fine. (Well apart from no logging of course!)

alixander commented 1 year ago

@mark-summerfield i think this is because slog made backward-incompatible changes without a major version bump. can you try changing your go.mod's slog version to the one in D2? https://github.com/terrastruct/d2/blob/master/go.mod#L6

searching around, there's no way for us to lock onto that version =. it's a todo to replace it

cc @nhooyr

mark-summerfield commented 1 year ago

I tried replacing in go.mod with this as you suggested:

require cdr.dev/slog v1.4.2

It didn't work at first, but then I deleted go.sum, did a go get and now it works fine. Thank you.

I don't want to close the issue though because surely it ought to be fixed?

alixander commented 1 year ago

oh right you have to do go mod tidy after making that change.

And yes, it ought to be fixed, will use this issue to track -- ty!