You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/07/22 23:23:08 UTC

[GitHub] [beam] lostluck commented on a change in pull request #15206: [Beam-10166] Improve execution time errors

lostluck commented on a change in pull request #15206:
URL: https://github.com/apache/beam/pull/15206#discussion_r675222275



##########
File path: sdks/go/pkg/beam/core/runtime/exec/util.go
##########
@@ -33,13 +34,29 @@ func (g *GenID) New() UnitID {
 	return UnitID(g.last)
 }
 
+type doFnError struct {
+	doFn string
+	err  error
+	uid  UnitID
+	pid  string
+}
+
+func (e *doFnError) Error() string {
+	return fmt.Sprintf("DoFn[<%d>;<%s>]<%s> returned error:<%s>", e.uid, e.pid, e.doFn, e.err)
+}
+
 // callNoPanic calls the given function and catches any panic.
 func callNoPanic(ctx context.Context, fn func(context.Context) error) (err error) {
 	defer func() {
 		if r := recover(); r != nil {
-			// Top level error is the panic itself, but also include the stack trace as the original error.
-			// Higher levels can then add appropriate context without getting pushed down by the stack trace.
-			err = errors.SetTopLevelMsgf(errors.Errorf("panic: %v %s", r, debug.Stack()), "panic: %v", r)
+			// check if error is of type DoFn then handle it appropriately

Review comment:
       Please change this comment to
   ```suggestion
   			// Check if the panic value is from a failed DoFn, and return it without a panic trace.
   ```
   
   A comment saying 'handle it appropriately' doesn't communicate anything to the reader. What does that mean?

##########
File path: sdks/go/pkg/beam/core/runtime/exec/util_test.go
##########
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package exec
+
+import (
+	"context"
+	"errors"
+	"strings"
+	"testing"
+
+	"github.com/apache/beam/sdks/go/pkg/beam/util/errorx"
+)
+
+// testSimpleError tests for a simple case that
+// doesn't panic
+func testSimpleError(ctx context.Context, t *testing.T) {
+	expected := errors.New("Sample error.")
+	actual := callNoPanic(ctx, func(c context.Context) error { return errors.New("Simple error.") })
+
+	if errors.Unwrap(actual) != errors.Unwrap(expected) {
+		t.Errorf("Simple error reporting failed.")
+	}
+}
+
+// testPanicError tests for the case in which a normal
+// error is passed to panic, resulting in panic trace.
+func testPanicError(ctx context.Context, t *testing.T) {
+	actual := callNoPanic(ctx, func(c context.Context) error { panic("Panic error") })
+	if !strings.Contains(actual.Error(), "panic:") {
+		t.Errorf("Caught in panic.")
+	}
+}
+
+// testWrapPanicError tests for the case in which error
+// is passed to panic from DoFn, resulting in
+// formatted error message for DoFn.
+func testWrapPanicError(ctx context.Context, t *testing.T) {
+	parDoError := doFnError{
+		doFn: "sumFn",
+		err:  errors.New("SumFn error"),
+		uid:  1,
+		pid:  "Plan ID",
+	}
+	var err errorx.GuardedError
+	err.TrySetError(&parDoError)
+	actual := callNoPanic(ctx, func(c context.Context) error { panic(parDoError) })
+
+	if strings.Contains(actual.Error(), "panic:") {
+		t.Errorf("Error not wrapped! Caught in panic")
+	}
+}
+
+func TestCallNoPanic(t *testing.T) {

Review comment:
       Split this into the 3 separate test functions instead of doing it like this. There's no reason to make this a "single" test.
    
   In particular use an underscore to describe the cases
   
   func TestCallNoPanic_simpleError(t *testing.T) { ...}
   func TestCallNoPanic_panic(t *testing.T) { ...}
   func TestCallNoPanic_wrappedPanic(t *testing.T) { ...}
   
   Testing in Go is well described in the testing package overview.: https://pkg.go.dev/testing#pkg-overview 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org