Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Replace packr with embed fs #2166

Merged
merged 11 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ exclude_paths:
- "*_test.go"
- "**_test.go"
- "middleware_test.go"
- packrd/**.go
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
50 changes: 0 additions & 50 deletions Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions SHOULDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ Thank you to the following **GIANTS**:

* [github.com/gobuffalo/nulls](https://godoc.org/github.com/gobuffalo/nulls)

* [github.com/gobuffalo/packd](https://godoc.org/github.com/gobuffalo/packd)

* [github.com/gobuffalo/packr](https://godoc.org/github.com/gobuffalo/packr)

* [github.com/gobuffalo/packr/v2](https://godoc.org/github.com/gobuffalo/packr/v2)

* [github.com/gobuffalo/plush](https://godoc.org/github.com/gobuffalo/plush)

* [github.com/gobuffalo/plushgen](https://godoc.org/github.com/gobuffalo/plushgen)
Expand Down
1 change: 0 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func New(opts Options) *App {
c := a.newContext(RouteInfo{}, res, req)
err := fmt.Errorf(errorf, req.Method, req.URL.Path)
_ = a.ErrorHandlers.Get(code)(code, err, c)

}
}

Expand Down
5 changes: 3 additions & 2 deletions default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -15,7 +16,6 @@ import (
"time"

"github.com/gobuffalo/buffalo/binding"
"github.com/gobuffalo/buffalo/internal/takeon/github.com/markbates/errx"
"github.com/gobuffalo/buffalo/render"
)

Expand Down Expand Up @@ -129,7 +129,8 @@ func (d *DefaultContext) Render(status int, rr render.Renderer) error {

err := rr.Render(bb, data)
if err != nil {
if er, ok := errx.Unwrap(err).(render.ErrRedirect); ok {
var er render.ErrRedirect
if errors.As(err, &er) {
return d.Redirect(er.Status, er.URL)
}
return HTTPError{Status: http.StatusInternalServerError, Cause: err}
Expand Down
23 changes: 15 additions & 8 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"net/http"
"runtime/debug"
Expand All @@ -12,7 +13,6 @@ import (

"github.com/gobuffalo/buffalo/internal/defaults"
"github.com/gobuffalo/buffalo/internal/httpx"
"github.com/gobuffalo/buffalo/internal/takeon/github.com/markbates/errx"
"github.com/gobuffalo/events"
"github.com/gobuffalo/plush/v4"
)
Expand All @@ -23,6 +23,10 @@ type HTTPError struct {
Cause error `json:"error"`
}

func (h HTTPError) Unwrap() error {
return h.Cause
}

func (h HTTPError) Error() string {
return h.Cause.Error()
}
Expand Down Expand Up @@ -105,13 +109,13 @@ func (a *App) defaultErrorMiddleware(next Handler) Handler {
return nil
}
status := http.StatusInternalServerError
// unpack root cause and check for HTTPError
cause := errx.Unwrap(err)
switch cause {
case sql.ErrNoRows:
// unpack root err and check for HTTPError
switch {
case errors.Is(err, sql.ErrNoRows):
status = http.StatusNotFound
default:
if h, ok := cause.(HTTPError); ok {
var h HTTPError
if errors.As(err, &h) {
status = h.Status
}
}
Expand Down Expand Up @@ -183,13 +187,16 @@ func defaultErrorHandler(status int, origErr error, c Context) error {
}

trace := origErr.Error()
if cause := errors.Unwrap(origErr); cause != nil {
origErr = cause
}

switch strings.ToLower(requestCT) {
case "application/json", "text/json", "json":
c.Response().Header().Set("content-type", "application/json")

err := json.NewEncoder(c.Response()).Encode(errorResponseDefault(defaultErrorResponse, &ErrorResponse{
Error: errx.Unwrap(origErr).Error(),
Error: origErr.Error(),
Trace: trace,
Code: status,
}))
Expand All @@ -199,7 +206,7 @@ func defaultErrorHandler(status int, origErr error, c Context) error {
case "application/xml", "text/xml", "xml":
c.Response().Header().Set("content-type", "text/xml")
err := xml.NewEncoder(c.Response()).Encode(errorResponseDefault(defaultErrorResponse, &ErrorResponse{
Error: errx.Unwrap(origErr).Error(),
Error: origErr.Error(),
Trace: trace,
Code: status,
}))
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ require (
github.com/gobuffalo/events v1.4.2
github.com/gobuffalo/flect v0.2.4
github.com/gobuffalo/github_flavored_markdown v1.1.1
github.com/gobuffalo/helpers v0.6.3
github.com/gobuffalo/helpers v0.6.4
github.com/gobuffalo/httptest v1.5.1
github.com/gobuffalo/logger v1.0.6
github.com/gobuffalo/meta v0.3.1
github.com/gobuffalo/nulls v0.4.1
github.com/gobuffalo/packd v1.0.1
github.com/gobuffalo/packr/v2 v2.8.1
github.com/gobuffalo/plush/v4 v4.1.8
github.com/gobuffalo/pop/v5 v5.3.4
github.com/gobuffalo/tags/v3 v3.1.1
github.com/gobuffalo/plush/v4 v4.1.9
github.com/gobuffalo/pop/v6 v6.0.0
github.com/gobuffalo/tags/v3 v3.1.2
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/gorilla/sessions v1.2.1
Expand All @@ -30,6 +28,7 @@ require (
github.com/markbates/safe v1.0.1
github.com/markbates/sigtx v1.0.0
github.com/monoculum/formam v3.5.5+incompatible
github.com/psanford/memfs v0.0.0-20210214183328-a001468d78ef
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
Expand Down
Loading