StaticGenerator::requestPath() doesn't do anything with a request that produces a 500 error

Created on 17 January 2024, 5 months ago
Updated 31 January 2024, 5 months ago

Problem/Motivation

StaticGenerator::requestPath() checks for redirects and 200 responses:

    $destination = $this->getDestination($path);
    if ($response->isRedirection() || $response->isOk()) {

If the response is a 500, then nothing happens, and no error is returned to the user running the static export process.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs work

Version

1.0

Component

Tome Static

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • Assigned to Mohd Sahzad
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 5 months ago
    Waiting for branch to pass
  • 🇮🇳India Mohd Sahzad

    I have created the patch related to this issue. Please review the attached patch.

  • 🇬🇧United Kingdom joachim
    +++ b/modules/tome_static/src/StaticGenerator.php
    @@ -161,6 +161,16 @@ class StaticGenerator implements StaticGeneratorInterface {
         catch (\Exception $e) {
    +
    +      // Log the error for debugging purposes
    

    This shouldn't be in the catch() block -- that is for catching an exception caused by the system making the request.

    What this issue is about is dealing with the $response being a 500.

    As well as logging, we need to figure out a way to return an error to the user, whether that's Drush or Batch API, and also to the originator of the export so a failure can be registered with this: ✨ Add a finish event for static HTML generator batch Needs work .

  • Status changed to Needs work 5 months ago
  • 🇬🇧United Kingdom joachim

    I can add this in StaticGenerator:

        elseif ($response->isServerError()) {
          throw new \Exception();
        }
    

    and that exception is caught here in StaticExportPathCommand:

        foreach ($paths as $path) {
          $this->requestPreparer->prepareForRequest();
          try {
            $invoke_paths = array_merge($this->static->requestPath($path), $invoke_paths);
          }
          catch (\Exception $e) {
            $this->io->getErrorStyle()->error($this->formatPathException($path, $e));
          }
        }
    

    but that output that should be shown on the CLI isn't.

    Is Tome doing something to suppress that?

  • 🇬🇧United Kingdom joachim

    There is some sort of collection of errors from the process:

          if (!$is_running) {
            if (!$process->isSuccessful()) {
              $error_output = $process->getErrorOutput();
              $collected_errors[] = "Error when running \"{$command}\":\n  $error_output";
            }
    

    but that's only output if the process reports success.

Production build 0.69.0 2024