From 3700f78355fa559f30736573fa87ff27c4d82ef1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 15 Oct 2025 22:09:48 +0200 Subject: [PATCH] refactor: preserve exception chain in validation error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When catching and re-throwing exceptions, preserve the original exception chain by passing the caught exception as the third parameter to new Exception. This retains the full stack trace for debugging while keeping descriptive error messages. Changes: - validateDockerComposeForInjection(): 4 locations fixed - validateVolumeStringForInjection(): 3 locations fixed Before: throw new \Exception('Invalid Docker volume definition: '.$e->getMessage()); After: throw new \Exception('Invalid Docker volume definition: '.$e->getMessage(), 0, $e); Benefits: - Full stack trace preserved for debugging - Original exception context retained - Better error diagnostics in production logs All 60 security tests pass (176 assertions). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- bootstrap/helpers/parsers.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.php index 7ed6d8c7a..7cc084530 100644 --- a/bootstrap/helpers/parsers.php +++ b/bootstrap/helpers/parsers.php @@ -29,7 +29,7 @@ function validateDockerComposeForInjection(string $composeYaml): void try { $parsed = Yaml::parse($composeYaml); } catch (\Exception $e) { - throw new \Exception('Invalid YAML format: '.$e->getMessage()); + throw new \Exception('Invalid YAML format: '.$e->getMessage(), 0, $e); } if (! is_array($parsed) || ! isset($parsed['services']) || ! is_array($parsed['services'])) { @@ -42,7 +42,9 @@ function validateDockerComposeForInjection(string $composeYaml): void } catch (\Exception $e) { throw new \Exception( 'Invalid Docker Compose service name: '.$e->getMessage(). - ' Service names must not contain shell metacharacters.' + ' Service names must not contain shell metacharacters.', + 0, + $e ); } @@ -64,7 +66,9 @@ function validateDockerComposeForInjection(string $composeYaml): void } catch (\Exception $e) { throw new \Exception( 'Invalid Docker volume definition (array syntax): '.$e->getMessage(). - ' Please use safe path names without shell metacharacters.' + ' Please use safe path names without shell metacharacters.', + 0, + $e ); } } @@ -78,7 +82,9 @@ function validateDockerComposeForInjection(string $composeYaml): void } catch (\Exception $e) { throw new \Exception( 'Invalid Docker volume definition (array syntax): '.$e->getMessage(). - ' Please use safe path names without shell metacharacters.' + ' Please use safe path names without shell metacharacters.', + 0, + $e ); } } @@ -107,7 +113,9 @@ function validateVolumeStringForInjection(string $volumeString): void } catch (\Exception $e) { throw new \Exception( 'Invalid Docker volume definition: '.$e->getMessage(). - ' Please use safe names without shell metacharacters.' + ' Please use safe names without shell metacharacters.', + 0, + $e ); } @@ -125,7 +133,9 @@ function validateVolumeStringForInjection(string $volumeString): void } catch (\Exception $e) { throw new \Exception( 'Invalid Docker volume definition: '.$e->getMessage(). - ' Please use safe path names without shell metacharacters.' + ' Please use safe path names without shell metacharacters.', + 0, + $e ); } } @@ -136,7 +146,9 @@ function validateVolumeStringForInjection(string $volumeString): void } catch (\Exception $e) { throw new \Exception( 'Invalid Docker volume definition: '.$e->getMessage(). - ' Please use safe path names without shell metacharacters.' + ' Please use safe path names without shell metacharacters.', + 0, + $e ); } }