You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve template system and panic recovery (#24461)
Partially for #24457
Major changes:
1. The old `signedUserNameStringPointerKey` is quite hacky, use
`ctx.Data[SignedUser]` instead
2. Move duplicate code from `Contexter` to `CommonTemplateContextData`
3. Remove incorrect copying&pasting code `ctx.Data["Err_Password"] =
true` in API handlers
4. Use one unique `RenderPanicErrorPage` for panic error page rendering
5. Move `stripSlashesMiddleware` to be the first middleware
6. Install global panic recovery handler, it works for both `install`
and `web`
7. Make `500.tmpl` only depend minimal template functions/variables,
avoid triggering new panics
Screenshot:
<details>

</details>
ctx.PlainText(http.StatusInternalServerError, "Unable to find HTML templates, the template system is not initialized, or Gitea can't find your template files.")
err=fmt.Errorf("failed to render template: %s, error: %s", name, templates.HandleTemplateRenderingError(err))
235
-
ctx.ServerError("Render failed", err)
239
+
ctx.ServerError("Render failed", err) // show the 500 error page
240
+
} else {
241
+
ctx.PlainText(http.StatusInternalServerError, "Unable to render status/500 page, the template system is broken, or Gitea can't find your template files.")
// At the moment, Firefox (iOS) (10x) has an engine bug. See https://github.com/go-gitea/gitea/issues/20240
29
25
// If a script inserts a newly created (and content changed) element into DOM, there will be a nonsense error event reporting: Script error: line 0, col 0.
@@ -37,13 +33,6 @@ function initGlobalErrorHandler() {
37
33
if(!window.config){
38
34
showGlobalErrorMessage(`Gitea JavaScript code couldn't run correctly, please check your custom templates`);
39
35
}
40
-
if(window.config.initCount>1){
41
-
// when a sub-templates triggers an 500 error, its parent template has been partially rendered,
42
-
// then the 500 page will be rendered after that partially rendered page, which will cause the initCount > 1
43
-
// in this case, the page is totally broken, so do not do any further error handling
44
-
console.error('initGlobalErrorHandler: Gitea global config system has already been initialized, there must be something else wrong');
45
-
return;
46
-
}
47
36
// we added an event handler for window error at the very beginning of <script> of page head
48
37
// the handler calls `_globalHandlerErrors.push` (array method) to record all errors occur before this init
49
38
// then in this init, we can collect all error events and show them
0 commit comments