nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: tetratelabs/wazero
Pull request #545 (2022-05-12 04:54:52)

Implements errors.Is for sys.ExitError
Allows use with test assertions like `require.ErrorIs`, which delegates to `errors.Is` both here and in testify.

Cleans up a related TODO.

anuraaga: Thanks for the reminder - I'll leave it as is since it'll be common to only check the exit code instead of comparing to a full error outside of tests.

Patch:
diff --git a/sys/sys.go b/sys/sys.go
index 28539889..75f3159d 100644
--- a/sys/sys.go
+++ b/sys/sys.go
@@ -42,3 +42,11 @@ func (e *ExitError) ExitCode() uint32 {
 func (e *ExitError) Error() string {
 	return fmt.Sprintf("module %q closed with exit_code(%d)", e.moduleName, e.exitCode)
 }
+
+// Is allows use via errors.Is
+func (e *ExitError) Is(err error) bool {
+	if target, ok := err.(*ExitError); ok {
+		return e.moduleName == target.moduleName && e.exitCode == target.exitCode
+	}
+	return false
+}


Test patch:
diff --git a/sys/sys_test.go b/sys/sys_test.go
new file mode 100644
index 00000000..14b8fd78
--- /dev/null
+++ b/sys/sys_test.go
@@ -0,0 +1,60 @@
+package sys
+
+import (
+	"errors"
+	"testing"
+
+	"github.com/tetratelabs/wazero/internal/testing/require"
+)
+
+type notExitError struct {
+	moduleName string
+	exitCode   uint32
+}
+
+func (e *notExitError) Error() string {
+	return "not exit error"
+}
+
+func TestIs(t *testing.T) {
+	err := NewExitError("some module", 2)
+	for _, tc := range []struct {
+		name    string
+		target  error
+		matches bool
+	}{
+		{
+			name:    "same object",
+			target:  err,
+			matches: true,
+		},
+		{
+			name:    "same content",
+			target:  NewExitError("some module", 2),
+			matches: true,
+		},
+		{
+			name:    "different module name",
+			target:  NewExitError("not some module", 2),
+			matches: false,
+		},
+		{
+			name:    "different exit code",
+			target:  NewExitError("some module", 0),
+			matches: false,
+		},
+		{
+			name: "different type",
+			target: &notExitError{
+				moduleName: "some module",
+				exitCode:   2,
+			},
+			matches: false,
+		},
+	} {
+		t.Run(tc.name, func(t *testing.T) {
+			matches := errors.Is(err, tc.target)
+			require.Equal(t, tc.matches, matches)
+		})
+	}
+}
diff --git a/wasm_test.go b/wasm_test.go
index 38d3d012..b4e681f0 100644
--- a/wasm_test.go
+++ b/wasm_test.go
@@ -571,11 +571,10 @@ func TestClose(t *testing.T) {
 
 		// Modules closed so calls fail
 		_, err = func1.Call(testCtx)
-		// TODO: This could be neater with ErrorIs
-		require.Error(t, err, sys.NewExitError("mod1", tc.exitCode).Error())
+		require.ErrorIs(t, err, sys.NewExitError("mod1", tc.exitCode))
 
 		_, err = func2.Call(testCtx)
-		require.Error(t, err, sys.NewExitError("mod2", tc.exitCode).Error())
+		require.ErrorIs(t, err, sys.NewExitError("mod2", tc.exitCode))
 	}
 }
Repository: tetratelabs/wazero
Pull request #568 (2022-05-17 02:35:31)

Renames asm packages to match folder name
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>

I was looking into possibly bringing in func-e's linting config. There are currently tons of failures so may proceed with that very gradually. One easy one that particularly spams the console is not liking package names with underscores. Here we are already aliasing in all the imports anyways so it seems OK to let the packages match the folder name.


Patch:
diff --git a/internal/asm/amd64/assembler.go b/internal/asm/amd64/assembler.go
index 46c3688f..7f0cf3fc 100644
--- a/internal/asm/amd64/assembler.go
+++ b/internal/asm/amd64/assembler.go
@@ -1,4 +1,4 @@
-package asm_amd64
+package amd64
 
 import (
 	"github.com/tetratelabs/wazero/internal/asm"
diff --git a/internal/asm/amd64/consts.go b/internal/asm/amd64/consts.go
index f791c1b4..baf39d79 100644
--- a/internal/asm/amd64/consts.go
+++ b/internal/asm/amd64/consts.go
@@ -1,4 +1,4 @@
-package asm_amd64
+package amd64
 
 import "github.com/tetratelabs/wazero/internal/asm"
 
diff --git a/internal/asm/amd64/impl.go b/internal/asm/amd64/impl.go
index a83f1fda..5907ef07 100644
--- a/internal/asm/amd64/impl.go
+++ b/internal/asm/amd64/impl.go
@@ -1,4 +1,4 @@
-package asm_amd64
+package amd64
 
 import (
 	"bytes"
diff --git a/internal/asm/arm64/assembler.go b/internal/asm/arm64/assembler.go
index 5be6085e..80e1ab1f 100644
--- a/internal/asm/arm64/assembler.go
+++ b/internal/asm/arm64/assembler.go
@@ -1,4 +1,4 @@
-package asm_arm64
+package arm64
 
 import (
 	"github.com/tetratelabs/wazero/internal/asm"
diff --git a/internal/asm/arm64/consts.go b/internal/asm/arm64/consts.go
index e06cdeaf..5464870a 100644
--- a/internal/asm/arm64/consts.go
+++ b/internal/asm/arm64/consts.go
@@ -1,4 +1,4 @@
-package asm_arm64
+package arm64
 
 import (
 	"github.com/tetratelabs/wazero/internal/asm"
diff --git a/internal/asm/arm64/impl.go b/internal/asm/arm64/impl.go
index 734951cd..760d7a96 100644
--- a/internal/asm/arm64/impl.go
+++ b/internal/asm/arm64/impl.go
@@ -1,4 +1,4 @@
-package asm_arm64
+package arm64
 
 import (
 	"bytes"


Test patch:
diff --git a/internal/asm/amd64/impl_test.go b/internal/asm/amd64/impl_test.go
index 7fa95656..6a03c997 100644
--- a/internal/asm/amd64/impl_test.go
+++ b/internal/asm/amd64/impl_test.go
@@ -1,4 +1,4 @@
-package asm_amd64
+package amd64
 
 import (
 	"strconv"
diff --git a/internal/asm/arm64/impl_test.go b/internal/asm/arm64/impl_test.go
index 7b343f03..7e8eb719 100644
--- a/internal/asm/arm64/impl_test.go
+++ b/internal/asm/arm64/impl_test.go
@@ -1,4 +1,4 @@
-package asm_arm64
+package arm64
 
 import (
 	"testing"