nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goadesign/goa
Pull request #3634 (2025-01-14 11:24:49)

Use eval.InvalidArgError() to dsl.MapParams()
Related to https://github.com/goadesign/goa/pull/3536

raphael: Thank you!

Patch:
diff --git a/dsl/http.go b/dsl/http.go
index e99cf08c..fe26072d 100644
--- a/dsl/http.go
+++ b/dsl/http.go
@@ -755,7 +755,7 @@ func MapParams(args ...any) {
 	if len(args) > 0 {
 		mapName, ok = args[0].(string)
 		if !ok {
-			eval.ReportError("argument must be a string")
+			eval.InvalidArgError("string", args[0])
 		}
 	}
 	e.MapQueryParams = &mapName


Test patch:
diff --git a/eval/eval_test.go b/eval/eval_test.go
index bfda3764..d32d503a 100644
--- a/eval/eval_test.go
+++ b/eval/eval_test.go
@@ -20,6 +20,7 @@ func TestInvalidArgError(t *testing.T) {
 		"ErrorName (int)":      {func() { Type("name", func() { ErrorName(1, 2) }) }, "cannot use 2 (type int) as type name"},
 		"Example":              {func() { Example(1, 2) }, "cannot use 1 (type int) as type summary (string)"},
 		"Headers":              {func() { Headers(1) }, "cannot use 1 (type int) as type function"},
+		"MapParams":            {func() { Service("s", func() { Method("m", func() { HTTP(func() { MapParams(1) }) }) }) }, "cannot use 1 (type int) as type string"},
 		"OneOf (function)":     {func() { Type("name", func() { OneOf("name", "description", 1) }) }, "cannot use 1 (type int) as type function"},
 		"OneOf (string)":       {func() { Type("name", func() { OneOf("name", 1, func() {}) }) }, "cannot use 1 (type int) as type string"},
 		"Param":                {func() { API("name", func() { HTTP(func() { Params(1) }) }) }, "cannot use 1 (type int) as type function"},
Repository: goadesign/goa
Pull request #3635 (2025-01-22 11:25:54)

Use InvalidArgError() to dsl.Type() more
Related to https://github.com/goadesign/goa/pull/3536

raphael: Thank you!

Patch:
diff --git a/dsl/user_type.go b/dsl/user_type.go
index bdd67ecb..0c7041be 100644
--- a/dsl/user_type.go
+++ b/dsl/user_type.go
@@ -85,7 +85,7 @@ func Type(name string, args ...any) expr.UserType {
 		if len(args) == 2 {
 			d, ok := args[1].(func())
 			if !ok {
-				eval.ReportError("third argument must be a function")
+				eval.InvalidArgError("function", args[1])
 				return nil
 			}
 			fn = d


Test patch:
diff --git a/eval/eval_test.go b/eval/eval_test.go
index d32d503a..79554fad 100644
--- a/eval/eval_test.go
+++ b/eval/eval_test.go
@@ -29,6 +29,7 @@ func TestInvalidArgError(t *testing.T) {
 		"Security":             {func() { Security(1) }, "cannot use 1 (type int) as type security scheme or security scheme name"},
 		"Security (typed nil)": {func() { Security((*expr.SchemeExpr)(nil)) }, "cannot use (*expr.SchemeExpr)(nil) (type *expr.SchemeExpr) as type security scheme"},
 		"Type":                 {func() { Type("name", 1) }, "cannot use 1 (type int) as type type or function"},
+		"Type (DataType)":      {func() { Type("name", String, 1) }, "cannot use 1 (type int) as type function"},
 	}
 	for name, tc := range dsls {
 		t.Run(name, func(t *testing.T) {
Repository: goadesign/goa
Pull request #3658 (2025-02-23 08:32:20)

Use eval.InvalidArgError() to dsl.Body() more
Related to https://github.com/goadesign/goa/pull/3536


Patch:
diff --git a/dsl/http.go b/dsl/http.go
index 826d6f53..f6aaf7e3 100644
--- a/dsl/http.go
+++ b/dsl/http.go
@@ -972,7 +972,8 @@ func Body(args ...any) {
 			var ok bool
 			fn, ok = args[1].(func())
 			if !ok {
-				eval.ReportError("second argument must be a function")
+				eval.InvalidArgError("function", args[1])
+				return
 			}
 		}
 	case expr.UserType:
@@ -981,7 +982,8 @@ func Body(args ...any) {
 			var ok bool
 			fn, ok = args[1].(func())
 			if !ok {
-				eval.ReportError("second argument must be a function")
+				eval.InvalidArgError("function", args[1])
+				return
 			}
 		}
 	case func():


Test patch:
diff --git a/eval/eval_test.go b/eval/eval_test.go
index 79554fad..5d37f55f 100644
--- a/eval/eval_test.go
+++ b/eval/eval_test.go
@@ -10,12 +10,18 @@ import (
 )
 
 func TestInvalidArgError(t *testing.T) {
+	var (
+		p  = func() { Attribute("a") }
+		ut = Type("ut", func() { Attribute("a") })
+	)
 	dsls := map[string]struct {
 		dsl  func()
 		want string
 	}{
 		"Attribute":            {func() { Type("name", func() { Attribute("name", String, "description", 1) }) }, "cannot use 1 (type int) as type func()"},
 		"Body":                 {func() { Service("s", func() { Method("m", func() { HTTP(func() { Body(1) }) }) }) }, "cannot use 1 (type int) as type attribute name, user type or DSL"},
+		"Body (string)":        {func() { Service("s", func() { Method("m", func() { Payload(p); HTTP(func() { Body("a", 1) }) }) }) }, "cannot use 1 (type int) as type function"},
+		"Body (UserType)":      {func() { Service("s", func() { Method("m", func() { HTTP(func() { Body(ut, 1) }) }) }) }, "cannot use 1 (type int) as type function"},
 		"ErrorName (bool)":     {func() { Type("name", func() { ErrorName(true) }) }, "cannot use true (type bool) as type name or position"},
 		"ErrorName (int)":      {func() { Type("name", func() { ErrorName(1, 2) }) }, "cannot use 2 (type int) as type name"},
 		"Example":              {func() { Example(1, 2) }, "cannot use 1 (type int) as type summary (string)"},
Repository: goadesign/goa
Pull request #3689 (2025-04-01 14:40:55)

Use eval.InvalidArgError() to dsl.Payload()
Related to https://github.com/goadesign/goa/pull/3536


Patch:
diff --git a/dsl/payload.go b/dsl/payload.go
index 8dc9a41d..1d3b5d2b 100644
--- a/dsl/payload.go
+++ b/dsl/payload.go
@@ -176,13 +176,13 @@ func methodDSL(m *expr.MethodExpr, suffix string, p any, args ...any) *expr.Attr
 	case expr.DataType:
 		att = &expr.AttributeExpr{Type: actual}
 	default:
-		eval.ReportError("invalid %s argument, must be a type or a function", suffix)
+		eval.InvalidArgError("type or function", p)
 		return nil
 	}
 	if len(args) >= 1 {
 		if f, ok := args[len(args)-1].(func()); ok {
 			if fn != nil {
-				eval.ReportError("invalid arguments in %s call, must be (type), (func), (type, func), (type, desc) or (type, desc, func)", suffix)
+				eval.InvalidArgError("(type), (func), (type, func), (type, desc) or (type, desc, func)", f)
 			}
 			fn = f
 		}


Test patch:
diff --git a/eval/eval_test.go b/eval/eval_test.go
index 5d37f55f..d334fec1 100644
--- a/eval/eval_test.go
+++ b/eval/eval_test.go
@@ -30,6 +30,8 @@ func TestInvalidArgError(t *testing.T) {
 		"OneOf (function)":     {func() { Type("name", func() { OneOf("name", "description", 1) }) }, "cannot use 1 (type int) as type function"},
 		"OneOf (string)":       {func() { Type("name", func() { OneOf("name", 1, func() {}) }) }, "cannot use 1 (type int) as type string"},
 		"Param":                {func() { API("name", func() { HTTP(func() { Params(1) }) }) }, "cannot use 1 (type int) as type function"},
+		"Payload":              {func() { Service("s", func() { Method("m", func() { Payload(1) }) }) }, "cannot use 1 (type int) as type type or function"},
+		"Payload (args)":       {func() { Service("s", func() { Method("m", func() { Payload(func() {}, func() {}) }) }) }, "(type func()) as type (type), (func), (type, func), (type, desc) or (type, desc, func)"},
 		"Response":             {func() { Service("s", func() { HTTP(func() { Response(1) }) }) }, "cannot use 1 (type int) as type name of error"},
 		"ResultType":           {func() { ResultType("identifier", 1) }, "cannot use 1 (type int) as type function or string"},
 		"Security":             {func() { Security(1) }, "cannot use 1 (type int) as type security scheme or security scheme name"},
Repository: pyccel/pyccel
Pull request #2140 (2025-01-09 17:13:06)

Fix removal of `test_node` when `rhs.current_user_node` becomes `PyccelAssociativeParenthesis`
This PR fixes an issue where attempting to remove `test_node` from `rhs` fails when `rhs.current_user_node` becomes a `PyccelAssociativeParenthesis` during the `operator(lhs, rhs)` operation. This happens when `rhs` contains more than one element, the `operator(lhs, rhs)` call creates a `PyccelAssociativeParenthesis`, which becomes the `current_user_node` of `rhs`. As a result, a direct call to `rhs.remove_user_node(test_node)` fails since `test_node` no longer matches the `current_user_node`.



jalalium: /bot checklist
pyccel-bot[bot]: Hey @pyccel/pyccel-dev ! @jalalium has just created this great new pull request! Check it out and let me know what you think!


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c026f5ef..3f5b0950 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -101,6 +101,7 @@ All notable changes to this project will be documented in this file.
 -   #2111 : Fix declaration of class attributes with name conflicts using type annotations.
 -   #2115 : Fix integer handling with NumPy 2.0 on Windows.
 -   Fix handling of union `typing.TypeAlias` objects as type hints.
+-   #2141 : Fix error when removing `test_node`
 
 ### Changed
 
diff --git a/pyccel/parser/semantic.py b/pyccel/parser/semantic.py
index f66f3dc7..a5a4a7f3 100644
--- a/pyccel/parser/semantic.py
+++ b/pyccel/parser/semantic.py
@@ -3652,7 +3652,12 @@ class SemanticParser(BasicParser):
             test_node = None
         if test_node:
             lhs.remove_user_node(test_node, invalidate = False)
-            rhs.remove_user_node(test_node, invalidate = False)
+            if test_node in rhs.get_all_user_nodes():
+                rhs.remove_user_node(test_node, invalidate = False)
+            else:
+                assert isinstance(rhs.current_user_node, PyccelAssociativeParenthesis)
+                mid = rhs.current_user_node
+                rhs.remove_user_node(mid, invalidate=False)
             lhs = self._assign_lhs_variable(expr.lhs, self._infer_type(test_node), test_node,
                     new_expressions, is_augassign = True)
             lhs = self._optional_params.get(lhs, lhs)


Test patch:
diff --git a/tests/epyccel/test_epyccel_generators.py b/tests/epyccel/test_epyccel_generators.py
index 037ddeec..c9a470bf 100644
--- a/tests/epyccel/test_epyccel_generators.py
+++ b/tests/epyccel/test_epyccel_generators.py
@@ -198,3 +198,12 @@ def test_sum_range_overwrite(language):
     f_epyc = epyccel(f, language = language)
 
     assert f(x) == f_epyc(x)
+
+def test_sum_with_two_variables(language):
+    def f():
+        x = sum(i-j for i in range(10) for j in range(7))
+        return x
+
+    f_epyc = epyccel(f, language=language)
+
+    assert f() == f_epyc()
Repository: gobuffalo/buffalo
Pull request #1613 (2019-03-03 17:30:13)

adds binding.Bindable interface


Patch:
diff --git a/binding/bindable.go b/binding/bindable.go
new file mode 100644
index 00000000..4131f9cc
--- /dev/null
+++ b/binding/bindable.go
@@ -0,0 +1,10 @@
+package binding
+
+import "net/http"
+
+// Bindable when implemented, on a type
+// will override any Binders that have been
+// configured when using buffalo#Context.Bind
+type Bindable interface {
+	Bind(*http.Request) error
+}
diff --git a/binding/binding.go b/binding/binding.go
index 366bde31..dc494cd6 100644
--- a/binding/binding.go
+++ b/binding/binding.go
@@ -74,6 +74,10 @@ func Register(contentType string, fn Binder) {
 // is "application/xml" it will use "xml.NewDecoder". The default
 // binder is "https://github.com/monoculum/formam".
 func Exec(req *http.Request, value interface{}) error {
+	if ba, ok := value.(Bindable); ok {
+		return ba.Bind(req)
+	}
+
 	ct := httpx.ContentType(req)
 	if ct == "" {
 		return errors.New("blank content type")


Test patch:
diff --git a/binding/bindable_test.go b/binding/bindable_test.go
new file mode 100644
index 00000000..e88259ad
--- /dev/null
+++ b/binding/bindable_test.go
@@ -0,0 +1,28 @@
+package binding
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"testing"
+
+	"github.com/stretchr/testify/require"
+)
+
+type orbison struct {
+	bound bool
+}
+
+func (o *orbison) Bind(req *http.Request) error {
+	o.bound = true
+	return nil
+}
+
+func Test_Bindable(t *testing.T) {
+	r := require.New(t)
+
+	req := httptest.NewRequest("GET", "/", nil)
+	o := &orbison{}
+	r.False(o.bound)
+	r.NoError(Exec(req, o))
+	r.True(o.bound)
+}
Repository: gobuffalo/buffalo
Pull request #1628 (2019-03-15 17:08:25)

Using safe for simple worker


Patch:
diff --git a/runtime/version.go b/runtime/version.go
index 00a3d2e1..a9e461e1 100644
--- a/runtime/version.go
+++ b/runtime/version.go
@@ -1,4 +1,4 @@
 package runtime
 
 // Version is the current version of the buffalo binary
-const Version = "v0.14.1"
+const Version = "v0.14.2"
diff --git a/worker/simple.go b/worker/simple.go
index ac1a62a9..df2c6f04 100644
--- a/worker/simple.go
+++ b/worker/simple.go
@@ -5,6 +5,7 @@ import (
 	"sync"
 	"time"
 
+	"github.com/markbates/safe"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 )
@@ -82,7 +83,10 @@ func (w Simple) Perform(job Job) error {
 	defer w.moot.Unlock()
 	if h, ok := w.handlers[job.Handler]; ok {
 		go func() {
-			err := h(job.Args)
+			err := safe.RunE(func() error {
+				return h(job.Args)
+			})
+
 			if err != nil {
 				w.Logger.Error(err)
 			}


Test patch:
diff --git a/worker/simple_test.go b/worker/simple_test.go
index 0d7d93fc..6372d60c 100644
--- a/worker/simple_test.go
+++ b/worker/simple_test.go
@@ -46,6 +46,31 @@ func Test_Simple_PerformAt(t *testing.T) {
 	r.True(hit)
 }
 
+func Test_Simple_PerformBroken(t *testing.T) {
+	r := require.New(t)
+
+	var hit bool
+	wg := &sync.WaitGroup{}
+	wg.Add(1)
+
+	w := NewSimple()
+	w.Register("x", func(Args) error {
+		hit = true
+		wg.Done()
+
+		//Index out of bounds on purpose
+		println([]string{}[0])
+
+		return nil
+	})
+
+	w.Perform(Job{
+		Handler: "x",
+	})
+	wg.Wait()
+	r.True(hit)
+}
+
 func Test_Simple_PerformIn(t *testing.T) {
 	r := require.New(t)
Repository: gobuffalo/buffalo
Pull request #1826 (2019-11-06 16:45:00)

Task middleware remove
This introduces the `Remove` method to MiddlewareStack. The use case for this is when you want an entire group to jump certain middleware that you have defined at a higher level of the app.

```go
....
app.Use(authorizedAccess)

g := app.Group("/public")

g.GET("/", publicHome)
g.GET("/landing1", firstLanding)
g.GET("/landing2", secondLanding)

g.Middleware.Remove(authorizedAccess)
//Would be the same as
//g.Middleware.Skip(authorizedAccess, publicHome, firstLanding, thirdLanding)
```



Patch:
diff --git a/middleware.go b/middleware.go
index a93e7719..1f2ec152 100644
--- a/middleware.go
+++ b/middleware.go
@@ -71,6 +71,29 @@ func (ms *MiddlewareStack) Use(mw ...MiddlewareFunc) {
 	ms.stack = append(ms.stack, mw...)
 }
 
+// Remove the specified Middleware(s) for the App/group. This is useful when
+// the middleware will be skipped by the entire group.
+/*
+	a.Middleware.Remove(Authorization)
+*/
+func (ms *MiddlewareStack) Remove(mws ...MiddlewareFunc) {
+	result := []MiddlewareFunc{}
+
+base:
+	for _, existing := range ms.stack {
+		for _, banned := range mws {
+			if funcKey(existing) == funcKey(banned) {
+				continue base
+			}
+		}
+
+		result = append(result, existing)
+	}
+
+	ms.stack = result
+
+}
+
 // Skip a specified piece of middleware the specified Handlers.
 // This is useful for things like wrapping your application in an
 // authorization middleware, but skipping it for things the home


Test patch:
diff --git a/middleware_test.go b/middleware_test.go
index 9bd7aacf..abd7b0e4 100644
--- a/middleware_test.go
+++ b/middleware_test.go
@@ -199,3 +199,46 @@ func Test_Middleware_Clear(t *testing.T) {
 	r.Len(mws.stack, 0)
 	r.Len(mws.skips, 0)
 }
+
+func Test_Middleware_Remove(t *testing.T) {
+	r := require.New(t)
+	log := []string{}
+
+	mw1 := func(h Handler) Handler {
+		log = append(log, "mw1")
+		return h
+	}
+
+	mw2 := func(h Handler) Handler {
+		log = append(log, "mw2")
+		return h
+	}
+
+	a := New(Options{})
+	a.Use(mw2)
+	a.Use(mw1)
+
+	var cr Resource = &carsResource{}
+	g := a.Resource("/autos", cr)
+	g.Middleware.Remove(mw2)
+
+	a.Resource("/all_log_autos", cr)
+	w := httptest.New(a)
+
+	ng := a.Resource("/no_log_autos", cr)
+	ng.Middleware.Remove(mw1, mw2)
+
+	_ = w.HTML("/autos/1").Get()
+	r.Len(log, 1)
+	r.Equal("mw1", log[0])
+
+	log = []string{}
+	_ = w.HTML("/all_log_autos/1").Get()
+	r.Len(log, 2)
+	r.Contains(log, "mw2")
+	r.Contains(log, "mw1")
+
+	log = []string{}
+	_ = w.HTML("/no_log_autos/1").Get()
+	r.Len(log, 0)
+}
Repository: gobuffalo/buffalo
Pull request #2119 (2021-07-06 10:31:37)

More reliable fix for Go 1.16 build issues
In my last PR https://github.com/gobuffalo/buffalo/pull/2113 I tried to solve the issue https://github.com/gobuffalo/buffalo/issues/2074 that a buffalo build fails when using Go 1.16.

My previous PR seems not to be a reliable fix. This change should more reliably fix dependency issues during a buffalo build.


Patch:
diff --git a/genny/build/apkg.go b/genny/build/apkg.go
index baed67c9..9a5479a6 100644
--- a/genny/build/apkg.go
+++ b/genny/build/apkg.go
@@ -1,6 +1,8 @@
 package build
 
 import (
+	"os/exec"
+
 	"github.com/gobuffalo/genny/v2"
 )
 
@@ -13,10 +15,15 @@ func apkg(opts *Options) (*genny.Generator, error) {
 
 	g.RunFn(copyInflections)
 	g.RunFn(copyDatabase)
+	g.RunFn(addDependencies)
 
 	return g, nil
 }
 
+func addDependencies(r *genny.Runner) error {
+	return r.Exec(exec.Command("go", "get", "-d"))
+}
+
 func copyDatabase(r *genny.Runner) error {
 	defer func() {
 		r.Disk.Remove("database.yml")
diff --git a/genny/build/build-packr.go b/genny/build/build-packr.go
deleted file mode 100644
index 9a999f39..00000000
--- a/genny/build/build-packr.go
+++ /dev/null
@@ -1,8 +0,0 @@
-// +build !skippackr
-// Code generated by github.com/gobuffalo/packr/v2. DO NOT EDIT.
-
-// You can use the "packr clean" command to clean up this,
-// and any other packr generated files.
-package build
-
-import _ "github.com/gobuffalo/buffalo/packrd"


Test patch:
diff --git a/genny/build/build_test.go b/genny/build/build_test.go
index 6d187c71..cfb73d8a 100644
--- a/genny/build/build_test.go
+++ b/genny/build/build_test.go
@@ -56,7 +56,7 @@ func Test_New(t *testing.T) {
 	// we should never leave any files modified or dropped
 	r.Len(res.Files, 0)
 
-	cmds := []string{"go build -tags bar -o bin/foo", "go mod tidy"}
+	cmds := []string{"go get -d", "go build -tags bar -o bin/foo", "go mod tidy"}
 	r.Len(res.Commands, len(cmds))
 	for i, c := range res.Commands {
 		eq(r, cmds[i], c)
@@ -84,7 +84,7 @@ func Test_NewWithoutBuildDeps(t *testing.T) {
 
 		res := run.Results()
 
-		cmds := []string{"go build -tags bar -o bin/foo"}
+		cmds := []string{"go get -d", "go build -tags bar -o bin/foo"}
 		r.Len(res.Commands, len(cmds))
 		for i, c := range res.Commands {
 			eq(r, cmds[i], c)
Repository: gobuffalo/buffalo
Pull request #2178 (2021-11-27 06:27:51)

hotfix: allowing leading slash when call r.HTML(template_name)
Previously, we allowed a leading slash in the template name when calling `r.HTML("resources/index.plush.html")` which is actually not required. (as I remember it was different by versions) Also, we generated actions with or without leading slashes before. (also different by `buffalo` versions.)

This hotfix makes buffalo keep the behavior so the user can migrate their existing code with a small modification as possible.

fixes gobuffalo/cli#55


Patch:
diff --git a/render/html.go b/render/html.go
index 48d93255..0b54af4c 100644
--- a/render/html.go
+++ b/render/html.go
@@ -2,6 +2,7 @@ package render
 
 import (
 	"html"
+	"strings"
 
 	"github.com/gobuffalo/github_flavored_markdown"
 	"github.com/gobuffalo/plush/v4"
@@ -28,6 +29,14 @@ func HTML(names ...string) Renderer {
 // in the options, then that layout file will be used
 // automatically.
 func (e *Engine) HTML(names ...string) Renderer {
+	// just allow leading slash and remove them here.
+	// generated actions were various by buffalo versions.
+	tmp := []string{}
+	for _, name := range names {
+		tmp = append(tmp, strings.TrimPrefix(name, "/"))
+	}
+	names = tmp
+
 	if e.HTMLLayout != "" && len(names) == 1 {
 		names = append(names, e.HTMLLayout)
 	}
diff --git a/runtime/version.go b/runtime/version.go
index 2eca1b0c..dcec814e 100644
--- a/runtime/version.go
+++ b/runtime/version.go
@@ -1,4 +1,4 @@
 package runtime
 
 // Version is the current version of the buffalo binary
-var Version = "v0.18.0"
+var Version = "v0.18.1"


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 619c466d..7e09bfbe 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -2,7 +2,7 @@ name: Tests
 on:
   push:
     branches:
-      - master
+      - main
   pull_request:
 
 jobs:
diff --git a/render/html_test.go b/render/html_test.go
index c31ce75b..f5f269d1 100644
--- a/render/html_test.go
+++ b/render/html_test.go
@@ -68,3 +68,22 @@ func Test_HTML_WithLayout_Override(t *testing.T) {
 	r.NoError(h.Render(bb, Data{"name": "Mark"}))
 	r.Equal("<html>Mark</html>", strings.TrimSpace(bb.String()))
 }
+
+func Test_HTML_LeadingSlash(t *testing.T) {
+	r := require.New(t)
+
+	rootFS := memfs.New()
+	r.NoError(rootFS.WriteFile(htmlTemplate, []byte("<%= name %>"), 0644))
+	r.NoError(rootFS.WriteFile(htmlLayout, []byte("<body><%= yield %></body>"), 0644))
+
+	e := NewEngine()
+	e.TemplatesFS = rootFS
+	e.HTMLLayout = htmlLayout
+
+	h := e.HTML("/my-template.html") // instead of "my-template.html"
+	r.Equal("text/html; charset=utf-8", h.ContentType())
+	bb := &bytes.Buffer{}
+
+	r.NoError(h.Render(bb, Data{"name": "Mark"}))
+	r.Equal("<body>Mark</body>", strings.TrimSpace(bb.String()))
+}
Repository: gobuffalo/buffalo
Pull request #2186 (2021-12-09 16:42:55)

Buffalo should respect http status when returning error
When returning an HTTP Status different than 404 caused by an "sql.ErrNoRows" buffalo is automatically changing the error status to a 404 error. Buffalo should respect the error status passed on the return.


Patch:
diff --git a/errors.go b/errors.go
index 4bfb667d..f9859541 100644
--- a/errors.go
+++ b/errors.go
@@ -112,14 +112,12 @@ func (a *App) defaultErrorMiddleware(next Handler) Handler {
 		}
 		status := http.StatusInternalServerError
 		// unpack root err and check for HTTPError
-		switch {
-		case errors.Is(err, sql.ErrNoRows):
+		if errors.Is(err, sql.ErrNoRows) {
 			status = http.StatusNotFound
-		default:
-			var h HTTPError
-			if errors.As(err, &h) {
-				status = h.Status
-			}
+		}
+		var h HTTPError
+		if errors.As(err, &h) {
+			status = h.Status
 		}
 		payload := events.Payload{
 			"context": c,


Test patch:
diff --git a/route_info_test.go b/route_info_test.go
index 4475c384..b24039cd 100644
--- a/route_info_test.go
+++ b/route_info_test.go
@@ -2,6 +2,7 @@ package buffalo
 
 import (
 	"database/sql"
+	"fmt"
 	"net/http"
 	"testing"
 
@@ -22,6 +23,18 @@ func Test_RouteInfo_ServeHTTP_SQL_Error(t *testing.T) {
 		return sql.ErrNoRows
 	})
 
+	app.GET("/bad-2", func(c Context) error {
+		return sql.ErrTxDone
+	})
+
+	app.GET("/gone-unwrap", func(c Context) error {
+		return c.Error(http.StatusGone, sql.ErrTxDone)
+	})
+
+	app.GET("/gone-wrap", func(c Context) error {
+		return c.Error(http.StatusGone, fmt.Errorf("some error wrapping here: %w", sql.ErrNoRows))
+	})
+
 	w := httptest.New(app)
 
 	res := w.HTML("/good").Get()
@@ -29,4 +42,10 @@ func Test_RouteInfo_ServeHTTP_SQL_Error(t *testing.T) {
 
 	res = w.HTML("/bad").Get()
 	r.Equal(http.StatusNotFound, res.Code)
+
+	res = w.HTML("/gone-wrap").Get()
+	r.Equal(http.StatusGone, res.Code)
+
+	res = w.HTML("/gone-unwrap").Get()
+	r.Equal(http.StatusGone, res.Code)
 }