Skip to content

Conversation

@AlexSkrypnyk
Copy link
Member

@AlexSkrypnyk AlexSkrypnyk commented Aug 6, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved error reporting when loading environment files, providing clearer feedback if parsing fails.
  • Tests

    • Expanded test coverage for environment file parsing, error handling, value conversion, and environment variable setting.

@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

The parseDotenv method in the Env utility was updated to implement explicit error capturing and reporting when parsing dotenv files, throwing exceptions on failure instead of returning empty arrays. Corresponding unit tests were added to verify parsing behavior, error handling, file accessibility, value conversion, and environment variable setting.

Changes

Cohort / File(s) Change Summary
Env Parsing Logic
.vortex/installer/src/Utils/Env.php
Enhanced parseDotenv to capture and report parsing errors using a custom error handler, throwing exceptions with detailed messages on failure.
Unit Tests for Env
.vortex/installer/tests/Unit/EnvTest.php
Added comprehensive tests for parseDotenv, including valid/invalid cases, file access errors, value conversion, and environment variable setting, utilizing data providers and exception assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Test as PHPUnit Test
    participant Env as Env::parseDotenv
    participant File as .env File
    participant ErrorHandler as Custom Error Handler

    Test->>Env: Call parseDotenv(filename)
    Env->>File: Read contents
    alt File not readable
        Env-->>Test: Return []
    else File readable
        Env->>ErrorHandler: Install error handler
        Env->>Env: parse_ini_string(contents)
        ErrorHandler-->>Env: Capture errors/warnings
        Env->>ErrorHandler: Restore error handler
        alt Parsing failed
            Env-->>Test: Throw RuntimeException with errors
        else Parsing succeeded
            Env-->>Test: Return parsed array
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

In the warren, errors once hid,
Now Env’s nose sniffs what parsing did.
With tests that hop through every case,
Each bug and edge now has its place.
No more silent fails in the night—
Just clear exceptions, crisp and bright! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 phpcs (3.7.2)
.vortex/installer/src/Utils/Env.php

ERROR: Referenced sniff "Drupal" does not exist

Run "phpcs --help" for usage information

.vortex/installer/tests/Unit/EnvTest.php

ERROR: Referenced sniff "Drupal" does not exist

Run "phpcs --help" for usage information

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/fix-installer-warnings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to commit August 6, 2025 04:26 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb7934b and 23b22d1.

📒 Files selected for processing (2)
  • .vortex/installer/src/Utils/Env.php (1 hunks)
  • .vortex/installer/tests/Unit/EnvTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: the file utility class in .vortex/installer/src/utils/file.php extends alexskrypnyk\file\file, and m...
Learnt from: AlexSkrypnyk
PR: drevops/vortex#1693
File: .vortex/installer/src/Prompts/Handlers/Internal.php:52-52
Timestamp: 2025-06-01T08:10:15.903Z
Learning: The File utility class in .vortex/installer/src/Utils/File.php extends AlexSkrypnyk\File\File, and methods like collapseRepeatedEmptyLines() are available from this external parent class dependency.

Applied to files:

  • .vortex/installer/src/Utils/Env.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: build (1)
  • GitHub Check: build (0)
  • GitHub Check: vortex-test-workflow (2)
  • GitHub Check: vortex-test-workflow (3)
  • GitHub Check: vortex-test-workflow (0)
  • GitHub Check: vortex-test-installer (8.4)
  • GitHub Check: vortex-test-workflow (1)
  • GitHub Check: vortex-test-common
  • GitHub Check: vortex-test-deployment (1)
  • GitHub Check: vortex-test-installer (8.2)
  • GitHub Check: vortex-test-installer (8.3)
  • GitHub Check: vortex-test-deployment (0)
  • GitHub Check: vortex-test-docs
🔇 Additional comments (5)
.vortex/installer/tests/Unit/EnvTest.php (5)

203-223: Well-structured test method with comprehensive exception handling.

The test properly covers both success and failure scenarios for parseDotenv, with appropriate exception expectations and cleanup.


225-243: Comprehensive test data covering valid and invalid .env scenarios.

The data provider effectively tests various .env formats including quoted values, comments, and invalid syntax that should trigger exceptions.


245-262: Thorough testing of file accessibility edge cases.

Both test methods properly verify the fallback behavior when .env files are not accessible, with appropriate cleanup in the permission manipulation test.


264-290: Comprehensive testing of value conversion functionality.

The test method and data provider thoroughly cover all conversion scenarios in the toValue method, with appropriate strict assertions.


292-301: Simple and effective test for environment variable setting.

The test properly verifies the put method functionality with appropriate cleanup.

Comment on lines +97 to +120
set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$errors): bool {
$errors[] = [
'errno' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
];

return TRUE;
});

$result = parse_ini_string($contents);

restore_error_handler();

if ($result === FALSE) {
$message = array_reduce($errors ?? [], function (string $carry, array $error): string {
return $carry . $error['message'] . PHP_EOL;
}, '');

throw new \RuntimeException(sprintf('Unable to parse file %s: %s', $filename, $message));
}

return $result;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Excellent error handling implementation with minor initialization improvement needed.

The custom error handler implementation effectively captures and reports parsing errors, which directly addresses the PR objective of fixing installer warnings with invalid .env files.

Consider initializing the $errors variable for clarity:

+    $errors = [];
     set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$errors): bool {

This makes the code more explicit about the variable's initialization, even though the null coalescing operator on line 113 handles the undefined case.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$errors): bool {
$errors[] = [
'errno' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
];
return TRUE;
});
$result = parse_ini_string($contents);
restore_error_handler();
if ($result === FALSE) {
$message = array_reduce($errors ?? [], function (string $carry, array $error): string {
return $carry . $error['message'] . PHP_EOL;
}, '');
throw new \RuntimeException(sprintf('Unable to parse file %s: %s', $filename, $message));
}
return $result;
$errors = [];
set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$errors): bool {
$errors[] = [
'errno' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
];
return TRUE;
});
$result = parse_ini_string($contents);
restore_error_handler();
if ($result === FALSE) {
$message = array_reduce($errors ?? [], function (string $carry, array $error): string {
return $carry . $error['message'] . PHP_EOL;
}, '');
throw new \RuntimeException(sprintf('Unable to parse file %s: %s', $filename, $message));
}
return $result;
🤖 Prompt for AI Agents
In .vortex/installer/src/Utils/Env.php around lines 97 to 120, initialize the
$errors variable as an empty array before setting the custom error handler. This
makes the code clearer and more explicit about the variable's initialization,
avoiding reliance on the null coalescing operator later. Simply add $errors =
[]; before the set_error_handler call.

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.70%. Comparing base (cb7934b) to head (23b22d1).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1887      +/-   ##
===========================================
+ Coverage    78.37%   78.70%   +0.32%     
===========================================
  Files           85       85              
  Lines         5003     5019      +16     
  Branches        35       35              
===========================================
+ Hits          3921     3950      +29     
+ Misses        1082     1069      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AlexSkrypnyk AlexSkrypnyk added the AUTOMERGE Pull request has been approved and set to automerge label Aug 6, 2025
@AlexSkrypnyk AlexSkrypnyk merged commit 84b8c86 into develop Aug 6, 2025
30 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/fix-installer-warnings branch August 6, 2025 04:54
@github-project-automation github-project-automation bot moved this from BACKLOG to Release queue in Vortex Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AUTOMERGE Pull request has been approved and set to automerge

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants