handle cleanup error correctly

This commit is contained in:
Bernard Xie 2022-11-17 14:24:59 -08:00
parent 530c70445a
commit 93ed44c978
No known key found for this signature in database
GPG key ID: 3C3E0036CE0F892C
2 changed files with 6 additions and 3 deletions

View file

@ -120,7 +120,10 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
return err
}
defer func() {
err = pw.Cleanup()
cleanupErr := pw.Cleanup()
if cleanupErr != nil {
ms.Log.Error.Printf("error cleaning up playwright: %v", cleanupErr.Error())
}
}()
}

View file

@ -120,8 +120,8 @@ func ExportPNG(ms *xmain.State, page playwright.Page, svg []byte) (outputImage [
pngString := fmt.Sprintf("%v", pngInterface)
pngPrefix := "data:image/png;base64,"
if !strings.HasPrefix(pngString, pngPrefix) {
if len(pngString) > 20 {
pngString = pngString[0:20] + "..."
if len(pngString) > 50 {
pngString = pngString[0:50] + "..."
}
return nil, fmt.Errorf("invalid PNG: %v\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", pngString)
}