hiroshinishio / sample-website

https://sample-website-chi.vercel.app
1 stars 1 forks source link

GitAuto: test #45

Open gitauto-for-dev[bot] opened 3 months ago

gitauto-for-dev[bot] commented 3 months ago

Original issue: #44

Why the bug occurs

The bug occurs because the code does not handle the scenario where the file is not found in the filesystem. When the file is removed, the $response->cpanelresult->data does not contain the expected data, leading to an exception being thrown.

How to reproduce

  1. Ensure the file referenced in the code is removed from the filesystem.
  2. Access the functionality that triggers the code at CPanel.php:80.
  3. Observe that an exception is thrown due to the missing file.

How to fix

To fix the bug, we need to add a check to handle the case where the file is not found. This can be done by verifying if the $response->cpanelresult->data contains the expected data before proceeding. If the data is not present, we should return a meaningful error message or handle the scenario gracefully.

Changes made:

// Src/Library/CPanel.php

80:         $response = $this->getRequest("json-api", "cpanel", $parameters);
81:         $stats = $response->cpanelresult->data;
82:         if (empty($stats) || !isset($stats[0])) {
83:             return array(
84:                 "error" => "File not found or unable to get stats for file: " . $fullPath
85:             );
86:         }
87:         $ctime = date("H:i:s d/m/Y", $stats[0]->ctime);
88:         $mtime = date("H:i:s d/m/Y", $stats[0]->mtime);
89:         return array(
90:             "fullPath" => $fullPath,
91:             "dirname" => $pathInfo["dirname"],
92:             "basename" => $pathInfo["basename"],
93:             "size" => $stats[0]->size,
94:             "ctime" => $ctime,
95:             "mtime" => $mtime,
96:             "type" => $stats[0]->type,
97:             "humansize" => $stats[0]->humansize
98:         );

Test these changes locally

git checkout -b gitauto-wes/issue-#44-4ac0f606-9af4-4b9b-8f01-38651d0bf5ce
git pull origin gitauto-wes/issue-#44-4ac0f606-9af4-4b9b-8f01-38651d0bf5ce