Revert "Use xdefer to append issue creation message"

This reverts commit 49f0a049fe.
This commit is contained in:
Bernard Xie 2022-11-17 18:19:00 -08:00
parent 49f0a049fe
commit 3dc999e12c
No known key found for this signature in database
GPG key ID: 3C3E0036CE0F892C
3 changed files with 8 additions and 18 deletions

View file

@ -22,7 +22,6 @@ import (
"oss.terrastruct.com/d2/lib/png" "oss.terrastruct.com/d2/lib/png"
"oss.terrastruct.com/d2/lib/version" "oss.terrastruct.com/d2/lib/version"
"oss.terrastruct.com/d2/lib/xmain" "oss.terrastruct.com/d2/lib/xmain"
"oss.terrastruct.com/xdefer"
) )
func main() { func main() {
@ -123,7 +122,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
defer func() { defer func() {
cleanupErr := pw.Cleanup() cleanupErr := pw.Cleanup()
if cleanupErr != nil { if cleanupErr != nil {
ms.Log.Error.Printf(cleanupErr.Error()) ms.Log.Error.Printf("error cleaning up png exporter: %v", cleanupErr.Error())
} }
}() }()
} }
@ -156,7 +155,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
return nil return nil
} }
func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, inputPath, outputPath string, page playwright.Page) (_ []byte, err error) { func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, inputPath, outputPath string, page playwright.Page) ([]byte, error) {
input, err := ms.ReadPath(inputPath) input, err := ms.ReadPath(inputPath)
if err != nil { if err != nil {
return nil, err return nil, err
@ -177,7 +176,6 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, input
return nil, err return nil, err
} }
defer xdefer.Errorf(&err, "failed to compile d2 \nplease report this issue here: https://github.com/terrastruct/d2/issues/new")
svg, err := d2svg.Render(d) svg, err := d2svg.Render(d)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -332,6 +332,7 @@ func (w *watcher) compileLoop(ctx context.Context) error {
if filepath.Ext(w.outputPath) == ".png" && !w.pw.Browser.IsConnected() { if filepath.Ext(w.outputPath) == ".png" && !w.pw.Browser.IsConnected() {
newPW, err := w.pw.RestartBrowser() newPW, err := w.pw.RestartBrowser()
if err != nil { if err != nil {
err = fmt.Errorf("png exporter has disconnected")
w.ms.Log.Error.Print(err) w.ms.Log.Error.Print(err)
w.broadcast(&compileResult{ w.broadcast(&compileResult{
Err: err.Error(), Err: err.Error(),

View file

@ -12,7 +12,6 @@ import (
"github.com/playwright-community/playwright-go" "github.com/playwright-community/playwright-go"
"oss.terrastruct.com/d2/lib/xmain" "oss.terrastruct.com/d2/lib/xmain"
"oss.terrastruct.com/xdefer"
) )
type Playwright struct { type Playwright struct {
@ -22,8 +21,6 @@ type Playwright struct {
} }
func (pw *Playwright) RestartBrowser() (newPW Playwright, err error) { func (pw *Playwright) RestartBrowser() (newPW Playwright, err error) {
defer xdefer.Errorf(&err, "png exporter has disconnected\nplease report this issue here: https://github.com/terrastruct/d2/issues/new")
if err = pw.Browser.Close(); err != nil { if err = pw.Browser.Close(); err != nil {
return Playwright{}, err return Playwright{}, err
} }
@ -31,8 +28,6 @@ func (pw *Playwright) RestartBrowser() (newPW Playwright, err error) {
} }
func (pw *Playwright) Cleanup() (err error) { func (pw *Playwright) Cleanup() (err error) {
defer xdefer.Errorf(&err, "failed to clean up png exporter\nplease report this issue here: https://github.com/terrastruct/d2/issues/new")
if err = pw.Browser.Close(); err != nil { if err = pw.Browser.Close(); err != nil {
return err return err
} }
@ -62,9 +57,7 @@ func startPlaywright(pw *playwright.Playwright) (Playwright, error) {
}, nil }, nil
} }
func InitPlaywright() (_ Playwright, err error) { func InitPlaywright() (Playwright, error) {
defer xdefer.Errorf(&err, "failed to initialize png exporter\nplease report this issue here: https://github.com/terrastruct/d2/issues/new")
// check if playwright driver/browsers are installed and up to date // check if playwright driver/browsers are installed and up to date
// https://github.com/playwright-community/playwright-go/blob/8e8f670b5fa7ba5365ae4bfc123fea4aac359763/run.go#L64. // https://github.com/playwright-community/playwright-go/blob/8e8f670b5fa7ba5365ae4bfc123fea4aac359763/run.go#L64.
driver, err := playwright.NewDriver(&playwright.RunOptions{}) driver, err := playwright.NewDriver(&playwright.RunOptions{})
@ -80,7 +73,7 @@ func InitPlaywright() (_ Playwright, err error) {
cmd := exec.Command(driver.DriverBinaryLocation, "--version") cmd := exec.Command(driver.DriverBinaryLocation, "--version")
output, err := cmd.Output() output, err := cmd.Output()
if err != nil { if err != nil {
return Playwright{}, err return Playwright{}, fmt.Errorf("error installing png exporter: %v\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", err.Error())
} }
if !bytes.Contains(output, []byte(driver.Version)) { if !bytes.Contains(output, []byte(driver.Version)) {
err = playwright.Install() err = playwright.Install()
@ -89,7 +82,7 @@ func InitPlaywright() (_ Playwright, err error) {
} }
} }
} else { } else {
return Playwright{}, err return Playwright{}, fmt.Errorf("could not install png exporter: %v\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", err.Error())
} }
pw, err := playwright.Run() pw, err := playwright.Run()
@ -103,10 +96,8 @@ func InitPlaywright() (_ Playwright, err error) {
var genPNGScript string var genPNGScript string
func ExportPNG(ms *xmain.State, page playwright.Page, svg []byte) (outputImage []byte, err error) { func ExportPNG(ms *xmain.State, page playwright.Page, svg []byte) (outputImage []byte, err error) {
defer xdefer.Errorf(&err, "failed to export png")
if page == nil { if page == nil {
return nil, fmt.Errorf("png exporter was not initialized properly") return nil, fmt.Errorf("png exporter was not initialized properly\nplease report this issue here: https://github.com/terrastruct/d2/issues/new")
} }
encodedSVG := base64.StdEncoding.EncodeToString(svg) encodedSVG := base64.StdEncoding.EncodeToString(svg)
@ -121,7 +112,7 @@ func ExportPNG(ms *xmain.State, page playwright.Page, svg []byte) (outputImage [
if len(pngString) > 50 { if len(pngString) > 50 {
pngString = pngString[0:50] + "..." pngString = pngString[0:50] + "..."
} }
return nil, fmt.Errorf("invalid PNG: %v", pngString) return nil, fmt.Errorf("invalid PNG: %v\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", pngString)
} }
splicedPNGString := pngString[len(pngPrefix):] splicedPNGString := pngString[len(pngPrefix):]
return base64.StdEncoding.DecodeString(splicedPNGString) return base64.StdEncoding.DecodeString(splicedPNGString)