diff --git a/cmd/d2/main.go b/cmd/d2/main.go index c0207d19b..ebeb4fd29 100644 --- a/cmd/d2/main.go +++ b/cmd/d2/main.go @@ -214,22 +214,14 @@ func compile(ctx context.Context, ms *xmain.State, isWatching bool, plugin d2plu } svg, err = imgbundler.InlineLocal(ctx, ms, svg) if err != nil { - if !isWatching { - ms.Log.Error.Printf("missing/broken remote image(s), writing partial output: %v", err) - } else { - ms.Log.Debug.Printf("ignoring missing/broken local image(s) in watch mode: %v", err) - } + ms.Log.Error.Printf("missing/broken local image(s), writing partial output: %v", err) } out := svg if filepath.Ext(outputPath) == ".png" { svg, err = imgbundler.InlineRemote(ctx, ms, svg) if err != nil { - if !isWatching { - ms.Log.Error.Printf("missing/broken remote image(s), writing partial output: %v", err) - } else { - ms.Log.Debug.Printf("ignoring missing/broken remote image(s) in watch mode: %v", err) - } + ms.Log.Error.Printf("missing/broken remote image(s), writing partial output: %v", err) } out, err = png.ConvertSVG(ms, page, svg) @@ -246,7 +238,7 @@ func compile(ctx context.Context, ms *xmain.State, isWatching bool, plugin d2plu // 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 && ms.Log.Nerrors() > 0 { - os.Exit(1) + xmain.ExitErrorf(1, "errors logged while rendering, partial output written to %v", outputPath) } return svg, nil diff --git a/lib/imgbundler/imgbundler.go b/lib/imgbundler/imgbundler.go index ece6ecad4..82e7105b9 100644 --- a/lib/imgbundler/imgbundler.go +++ b/lib/imgbundler/imgbundler.go @@ -97,7 +97,6 @@ func inline(ctx context.Context, ms *xmain.State, svg []byte, isRemote bool) (_ for { select { case <-ctx.Done(): - ms.Log.Debug.Printf("there") return nil, fmt.Errorf("failed to wait for imgbundler workers: %w", ctx.Err()) case <-time.After(time.Second * 5): ms.Log.Info.Printf("fetching images...") @@ -114,7 +113,7 @@ func inline(ctx context.Context, ms *xmain.State, svg []byte, isRemote bool) (_ } } -var transport = http.DefaultTransport +var imgClient = &http.Client{} func fetch(ctx context.Context, href string) (string, error) { ctx, cancel := context.WithTimeout(ctx, time.Minute) @@ -125,8 +124,7 @@ func fetch(ctx context.Context, href string) (string, error) { return "", err } - client := &http.Client{Transport: transport} - imgResp, err := client.Do(req) + imgResp, err := imgClient.Do(req) if err != nil { return "", err } diff --git a/lib/imgbundler/imgbundler_test.go b/lib/imgbundler/imgbundler_test.go index d40753f08..2d9536506 100644 --- a/lib/imgbundler/imgbundler_test.go +++ b/lib/imgbundler/imgbundler_test.go @@ -90,7 +90,7 @@ width="328" height="587" viewBox="-100 -131 328 587">