-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[BUG] View: If errors are returned by the ViewRenderer - do not output a "half template" #1569
Comments
Another point is that if you use |
@Dexus This has to do with the |
Yes, but it supposed that the following fixes it: Lines 461 to 488 in 75d7fe7
Did you try the |
Hi @kataras
here my example: package main
import (
"bytes"
"encoding/base64"
"fmt"
"reflect"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/logger"
"github.com/kataras/iris/v12/middleware/recover"
"github.com/kataras/iris/v12/view"
)
var tmpl *view.JetEngine
// GetView return the view.JetEngine for later use
func GetView() *view.JetEngine {
return tmpl
}
// RegisterView for Iris and all View Helper
func RegisterView(app *iris.Application) *view.JetEngine {
tmpl = iris.Jet("views", ".jet") // <--
tmpl.Reload(true) // remove in production.
tmpl.AddFunc("base64", func(a view.JetArguments) reflect.Value {
a.RequireNumOfArguments("base64", 1, 1)
buffer := bytes.NewBuffer(nil)
fmt.Fprint(buffer, a.Get(0))
return reflect.ValueOf(base64.URLEncoding.EncodeToString(buffer.Bytes()))
})
app.RegisterView(tmpl) // <--
return tmpl
}
func main() {
app := iris.New()
app.Logger().SetLevel("info") //"debug"
// Optionally, add two built'n handlers
// that can recover from any http-relative panics
// and log the requests to the terminal.
app.Use(recover.New())
app.Use(logger.New())
RegisterView(app)
// BUG: The OnAnyErrorCode will work if this is commented
// but as soon as you uncomment it, the webpage get rendered and
// delivered unfinished to the client
//app.Use(iris.Compression)
app.OnAnyErrorCode(func(ctx iris.Context) {
err := ctx.GetErr()
if err != nil {
ctx.Text(err.Error())
return
}
ctx.Text(iris.StatusText(ctx.GetStatusCode()))
})
// Method: GET
// Resource: http://localhost:8080/plans
app.Get("/plans", func(ctx iris.Context) {
ctx.Record()
ctx.ViewData("demo", "123")
if err := ctx.View("pages/plans.jet"); err != nil {
ctx.SetErr(err)
ctx.StopWithStatus(iris.StatusInternalServerError)
}
})
app.Run(
iris.Addr(":8080"),
iris.WithoutServerError(iris.ErrServerClosed),
iris.WithCharset("utf-8"),
iris.WithOptimizations,
iris.WithResetOnFireErrorCode,
iris.WithPostMaxMemory(1024*1024*3),
)
} Template:
This works, but still causes problems if a |
Yes @Dexus, I see, the problem was that iris/_examples/routing/http-errors/reset-body/main.go Lines 1 to 42 in 39a1f00
Is that the solution you were looking for? |
Former-commit-id: c55f1023f4d93f6712c7fa4d299bcf1098872ecf
@Dexus that's strange, why you get an empty page? The error message doesn't shown up? Can you please create a repo that I can reproduce it? Thanks!! |
I will try to create a repo that have the exact same problem but without our code, this take some time, but try to finish it today. |
You can just create a simple jet view, with a runtime error, put the code you use, and the middlewares, I dont need your whole code base, just a small example that I can run and run until I fix the issue. Thanks @Dexus ! |
@kataras here your example: https://github.com/Dexus/iris-bug-examples please loog to the main.go and comment |
Oh is this the simplest example you could give me? :P I see many things like translation and view functions but it doesn't work it panics because locale files are missing, I will try to clean up, and get back to you soon. Also I want to know why you select to not use the Iris' i18n for localization which you can use on context methods and views as well, if there is something we can do to improve the iris i18n experience please let me know |
Just copy paste the most of it 😅 to not remove something that may have an impact.
Von meinem iPhone gesendet
… Am 26.07.2020 um 18:17 schrieb Gerasimos (Makis) Maropoulos ***@***.***>:
Oh is this the simplest example you could give me? :P I see many things like translation and view functions, I will take a look of it, and get back to you soon.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
OK @Dexus give it a try |
It works now. Thanks @kataras |
I thank you @Dexus, will take a look at the assesment for the certification of yours when I finish the documentation, I didnt forget it. I am freezing new features for v12.2.0. |
Describe the bug
I am currently using the latest version from the Master Branch. If I use a template with Jet that uses variables that are not present, an error is returned, but the template is already sent to the browser as far as it has come, this should be prevented.
To Reproduce
We have tried with and without
iris.WithResetOnFireErrorCode
but withoutctx.Record()
Expected behavior
Only the
StopWithText
should returned or theOnAnyErrorCode
should be triggered. Not the half rendered Template.I would expect, if a ViewEngine throws an error, that there will be no normal output, even if the template system has already sent it to the output.
An alternative would be to document it more clearly, in connection with the ViewEngines.
The text was updated successfully, but these errors were encountered: