atjiu / pybbs

更实用的Java开发的社区(论坛),Better use of Java development community (forum)
GNU Affero General Public License v3.0
1.87k stars 711 forks source link

freemarker.core.InvalidReferenceException in notification #160

Closed li-sui closed 3 years ago

li-sui commented 3 years ago

Envrioment: -Version 5.0 -Jdk: 1.8.0_202

error mesage:

Thu Oct 28 15:35:15 NZDT 2021
There was an unexpected error (type=Internal Server Error, status=500).
Request processing failed; nested exception is freemarker.core.InvalidReferenceException: The following has evaluated to null or missing: ==> _user [in template "theme/default/notifications.ftl" at line 12, column 43] ---- Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #macro notification userId read limit [in template "theme/default/components/notification.ftl" in macro "notification" at line 1, column 1] - Reached through: @notification userId=_user.id read=0 ... [in template "theme/default/notifications.ftl" at line 12, column 21] ~ Reached through: #nested [in template "theme/default/layout/layout.ftl" in macro "html" at line 29, column 13] ~ Reached through: @html page_title="通知" page_tab="notif... [in template "theme/default/notifications.ftl" at line 2, column 1] ----

reproducible script curl: curl http://localhost:8080/notifications

intelliJ http client:

GET http://localhost:8080/notifications

li-sui commented 3 years ago

There are more 500 errors. The issue is missing request parameters. It should return 400 Bad request rather than 500. An error handler should be implemented to deal with different exceptions.

http://localhost:8080/admin/role/edit
http://localhost:8080/admin/admin_user/edit
There was an unexpected error (type=Internal Server Error, status=500).
Request processing failed; nested exception is freemarker.core.InvalidReferenceException: The following has evaluated to null or missing: ==> role [in template "admin/role/edit.ftl" at line 22, column 61] ---- Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: ${role.id} [in template "admin/role/edit.ftl" at line 22, column 59] ~ Reached through: #nested [in template "admin/layout/layout.ftl" in macro "html" at line 77, column 13] ~ Reached through: @html page_title="角色编辑" page_tab="aut... [in template "admin/role/edit.ftl" at line 2, column 1] ----