Skip to content

podhmo/panicerr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

panicerr

convert panic to error

func TestSimpleWithGoroutine(t *testing.T) {
	g, _ := errgroup.WithContext(context.Background())

	g.Go(func() (err error) {
		defer Recoverer("ok", &err)
		t.Log("ok")
		return nil
	})
	g.Go(func() (err error) {
		defer Recoverer("ng", &err)
		t.Log("ng")
		panic("hmm")
	})

	err := g.Wait()
	if err == nil {
		t.Errorf("expected error, but nil, something wrong")
	}

	if expected, actual := err.Error(), "ng hmm"; expected != actual {
		t.Errorf("expected message is %q, but actual is %q", expected, actual)
	}
}

About

convert panic to error

Resources

License

Stars

Watchers

Forks

Packages

No packages published