[ 
https://issues.apache.org/jira/browse/SLING-4630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14499275#comment-14499275
 ] 

Georg Henzler commented on SLING-4630:
--------------------------------------

Agreed, there are many technical exceptions in a post construct method, that 
deserve an error log entry in the log file. But there is also the content 
problems, that can be fixed by the author directly. You could argue validation 
directly in the dialog has to ensure, that only a correct state is eventually 
saved to the JCR, but in reality this alone is not enough. For instance a 
component could reference an image (or a content fragment) that exists at the 
time the content is created and that reference does not exist some time later. 
We have a mechanism in place that throws a certain exception 
("InvalidContentException") for those cases and the exception is handled in a 
component filter that shows "yellow" to the author with an exact message what 
the problem is (in contrary, any technical problems are shown with a generic 
message and "red" telling the author, that he CANNOT do anything and he can 
either try again later or file a bug). An alternative would be to handle 
"yellow" content exceptions in the component itself, but this would mean a lot 
of duplicated code across model beans (and it would be a pity handle a 
cross-cutting concern locally many times).

The described approach above works nicely except that there are error log 
entries for those content exceptions. Following the general best practice that 
exceptions never should be logged and rethrown, patch2 would already solve our 
problem (because it logs only the exceptions is does not rethrow, for the post 
construct there would be at most one exception).  



> Sling Models should not log exceptions in post construct methods as error
> -------------------------------------------------------------------------
>
>                 Key: SLING-4630
>                 URL: https://issues.apache.org/jira/browse/SLING-4630
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: Sling Models Implementation 1.1.0
>            Reporter: Georg Henzler
>         Attachments: SLING-4630-patch1.patch, SLING-4630-patch2.patch
>
>
> If a post construct method throws an exception, that is NOT a technical 
> problem but can be fixed by the user (e.g. some content problem that can be 
> fixed by an author directly), at the moment this is still logged as an error 
> in the log file (where it should really a debug log at most).  
> We could disable the error log for post construct messages completely 
> (patch1, solves the problem for ModelAdapterFactory.createModel() but for  
> ModelAdapterFactory.getAdapter() this would swallow the exception, also see 
> SLING-3709) or we just ensure, that for the case we throw the exception we 
> don't *throw and log* the exception (which is bad practice anyway, patch2). 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to