Explorer: Exception Messages Printed in Results
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3576615. --> Reported by: [robloach](https://www.drupal.org/user/61114) Related to !18 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>There are exceptions which messages are printed directly into the user interface. This can include sensitive data or file paths that sometimes we shouldn't expose to the user.</p> <pre>$form_state-&gt;set('result', [<br> 'error' =&gt; $this-&gt;t('Error: @message', ['@message' =&gt; $e-&gt;getMessage()]),<br>]);<br>$this-&gt;messenger()-&gt;addError($this-&gt;t('Failed to load document: @message', ['@message' =&gt; $e-&gt;getMessage()]));</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Come up with a set of Exceptions that the DocumentLoader can run into, throw those Exceptions, and have the Exception details logged instead of displayed to the end user.</p> <p>Something like....</p> <pre>$form_state-&gt;set('result', [<br> 'error' =&gt; $this-&gt;t('An error occurred while loading the document. See &lt;a href=":url"&gt;the logs&lt;/a&gt; for details.', [<br>&nbsp;&nbsp; ':url' =&gt; '/admin/reports/dblog',<br> ]),<br>]);<br>$this-&gt;getLogger('document_loader')-&gt;error(<br> 'Document Loader error: @message',<br> ['@message' =&gt; $e-&gt;getMessage(), 'exception' =&gt; $e],<br>);</pre><h3 id="summary-ui-changes">User interface changes</h3> <p>Rather than reading the exception directly, users are then asked to visit the logs, so that only site administrators can see it, and not just the users.</p> <h3 id="summary-api-changes">API changes</h3> <p>Perhaps some new Exceptions introduced for the Document Loader.</p> > Related issue: [Issue #3576934](https://www.drupal.org/node/3576934) > Related issue: [Issue #3575269](https://www.drupal.org/node/3575269)
issue