From 983b05bd9c756de331920546abbd4d22273b70fe Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 29 Nov 2022 13:50:48 -0800 Subject: [PATCH] 2022-11-29 01:50:48PM --- cmd/d2/main.go | 8 ++++---- lib/imgbundler/imgbundler.go | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/d2/main.go b/cmd/d2/main.go index 1a7e68eac..1750d86e5 100644 --- a/cmd/d2/main.go +++ b/cmd/d2/main.go @@ -205,24 +205,24 @@ func compile(ctx context.Context, ms *xmain.State, isWatching bool, plugin d2plu if err != nil { return nil, err } - svg, err = imgbundler.InlineLocal(ms, svg) + svg, err = imgbundler.InlineLocal(ctx, ms, svg) if err != nil { // Missing/broken images are fine during watch mode, as the user is likely building up a diagram. // Otherwise, the assumption is that this diagram is building for production, and broken images are not okay. if !isWatching { return nil, err } - ms.Log.Debug.Printf("ignoring missing/broken local image in watch mode: %v", err) + ms.Log.Debug.Printf("ignoring missing/broken local image(s) in watch mode: %v", err) } out := svg if filepath.Ext(outputPath) == ".png" { - svg, err = imgbundler.InlineRemote(ms, svg) + svg, err = imgbundler.InlineRemote(ctx, ms, svg) if err != nil { if !isWatching { return nil, err } - ms.Log.Debug.Printf("ignoring missing/broken remote image in watch mode: %v", err) + ms.Log.Debug.Printf("ignoring missing/broken remote image(s) in watch mode: %v", err) } out, err = png.ConvertSVG(ms, page, svg) diff --git a/lib/imgbundler/imgbundler.go b/lib/imgbundler/imgbundler.go index 0b1addc22..b999d3863 100644 --- a/lib/imgbundler/imgbundler.go +++ b/lib/imgbundler/imgbundler.go @@ -31,15 +31,15 @@ type resp struct { err error } -func InlineLocal(ms *xmain.State, in []byte) ([]byte, error) { - return inline(ms, in, false) +func InlineLocal(ctx context.Context, ms *xmain.State, in []byte) ([]byte, error) { + return inline(ctx, ms, in, false) } -func InlineRemote(ms *xmain.State, in []byte) ([]byte, error) { - return inline(ms, in, true) +func InlineRemote(ctx context.Context, ms *xmain.State, in []byte) ([]byte, error) { + return inline(ctx, ms, in, true) } -func inline(ms *xmain.State, svg []byte, isRemote bool) (_ []byte, err error) { +func inline(ctx context.Context, ms *xmain.State, svg []byte, isRemote bool) (_ []byte, err error) { defer xdefer.Errorf(&err, "failed to bundle images") imgs := imageRe.FindAllSubmatch(svg, -1) @@ -57,7 +57,7 @@ func inline(ms *xmain.State, svg []byte, isRemote bool) (_ []byte, err error) { // Limits the number of workers to 16. sema := make(chan struct{}, 16) - ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) + ctx, cancel := context.WithTimeout(ctx, time.Minute*5) defer cancel() wg.Add(len(filtered))