Module agent fails when enabling a module with missing dependencies, returning generic error in chatbot
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3541337. -->
Reported by: [sijumpk](https://www.drupal.org/user/389053)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>
When the module agent is instructed to enable a module that has a missing dependency, the process ends with an error in the chat interface.<br>
Instead of gracefully handling the dependency issue, the chatbot fails and shows the error<br>
<code>"An error occurred while fetching messages. Please try again."</code> while the logs report<br>
<code>"The chatbot had an error: We could not figure out which module you meant. Please specify better."</code>.<br>
This prevents the user from knowing the real cause (missing dependency) and breaks the conversation flow.
</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Set up a Drupal 11 installation with AI Agents enabled, or install the <a href="https://www.drupal.org/project/drupal_cms_ai">Drupal CMS AI recipe</a>.</li>
<li>Install the <a href="https://www.drupal.org/project/sitemap">Sitemap</a> module using:<br>
<pre>composer require 'drupal/sitemap:^2.0'</pre><p>
but do not enable it.
</p></li>
<li>Open the Drupal agent chatbot.</li>
<li>Type the prompt: <code>Install "Sitemap book" module</code>.</li>
<li>When asked for confirmation, type <code>yes</code>.</li>
<li>When it asks for confirmation to enable the "book" module, type <code>yes</code>.</li>
<li>Observe that an error appears in the chat:<br>
<code>"An error occurred while fetching messages. Please try again."</code>.
</li>
<li>Check the recent log messages and see the error:<br>
<code>"The chatbot had an error: We could not figure out which module you meant. Please specify better."</code>.
</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<ul>
<li>Update the module agent logic to detect when a module has unmet dependencies before attempting to enable it.</li>
<li>If dependencies are missing, return a clear message to the user listing the required modules instead of producing a generic error.</li>
<li>Ensure the chatbot does not break the conversation flow when encountering dependency issues.</li>
</ul>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<ul>
<li>Implement dependency check logic in the module enable handler.</li>
<li>Add proper error handling and user messaging for missing dependencies.</li>
</ul>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
issue