Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loads templates from embedded FS & improves Web UI errors #3

Merged
merged 2 commits into from
Jul 5, 2022
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
16 changes: 14 additions & 2 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package errata
import (
"bytes"
"embed"
"errors"
"fmt"
"io/fs"
"net/http"
Expand Down Expand Up @@ -130,8 +131,19 @@ func (s *Server) render(w http.ResponseWriter, path string, data pongo2.Context)
s.errorHandler(w, NewFileNotReadableErr(err, path))
}

tmpl, err := pongo2.FromBytes(b)
set := pongo2.NewSet("web", pongo2.NewFSLoader(web))

tmpl, err := set.FromBytes(b)
if err != nil {
// pongo2 needs errata!
if err, ok := err.(*pongo2.Error); ok {
var pathErr *fs.PathError
if err.OrigError.Error() == "unable to resolve template" || errors.As(err.OrigError, &pathErr) {
s.errorHandler(w, NewTemplateExecutionErr(err))
return
}
}

s.errorHandler(w, NewInvalidSyntaxErr(err, path))
return
}
Expand Down Expand Up @@ -195,7 +207,7 @@ func (s *Server) errorHandler(w http.ResponseWriter, err error) {
}
}

http.Error(w, err.Error(), statusCode)
http.Error(w, fmt.Sprintf("%+v", err), statusCode)
}

type HTTPStatusCodeExtractor interface {
Expand Down
4 changes: 2 additions & 2 deletions web/list.gohtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import "web/item.gohtml" erratum %}
{% import "web/sidebar.gohtml" sidebar %}
{% ssi "web/header.gohtml" %}
{% ssi "web/header.gohtml" parsed %}

<div class="docs-wrapper">
{{ sidebar(Errors) }}
Expand All @@ -21,4 +21,4 @@
</div>
</div><!--//docs-wrapper-->

{% ssi "web/footer.gohtml" %}
{% ssi "web/footer.gohtml" parsed %}
4 changes: 2 additions & 2 deletions web/search-miss.gohtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% ssi "web/header.gohtml" %}
{% ssi "web/header.gohtml" parsed %}

<div class="docs-wrapper">
<div class="docs-content">
Expand All @@ -10,4 +10,4 @@
</div>
</div><!--//docs-wrapper-->

{% ssi "web/footer.gohtml" %}
{% ssi "web/footer.gohtml" parsed %}
4 changes: 2 additions & 2 deletions web/single.gohtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import "web/item.gohtml" erratum %}
{% ssi "web/header.gohtml" %}
{% ssi "web/header.gohtml" parsed %}

<div class="docs-wrapper">
<div class="docs-content">
Expand All @@ -11,4 +11,4 @@
</div>
</div><!--//docs-wrapper-->

{% ssi "web/footer.gohtml" %}
{% ssi "web/footer.gohtml" parsed %}