Skip to content

add error message for ldap requirement#4139

Open
ildyria wants to merge 1 commit intomasterfrom
ldap
Open

add error message for ldap requirement#4139
ildyria wants to merge 1 commit intomasterfrom
ldap

Conversation

@ildyria
Copy link
Member

@ildyria ildyria commented Mar 2, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved system stability with enhanced error handling for the LDAP PHP extension. Added a pre-initialization check that displays a clear, user-friendly error message if the required extension is missing, preventing blank pages or cryptic errors.

@ildyria ildyria requested a review from a team as a code owner March 2, 2026 22:18
@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

The changes add an LDAP extension availability check to the application. A new error handler method in PanicAttack displays a 500 error if LDAP is missing, and a pre-flight check in index.php invokes this handler before normal initialization.

Changes

Cohort / File(s) Summary
LDAP Error Handler
bootstrap/PanicAttack.php
New ldap() method added to display a 500 error page when the LDAP PHP extension is not loaded.
Pre-flight Extension Check
public/index.php
Added early validation before app initialization to detect missing LDAP extension and trigger the error handler if not available.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop through the code, a check so divine,
"Is LDAP loaded?" we must first design,
When missing, we panic with grace and with flair,
No cryptic blank pages, just errors laid bare! 🌿

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
bootstrap/PanicAttack.php (1)

133-140: Inconsistent brace placement and extra blank line.

The opening brace should be on a new line to match the rest of the file (PSR-12 style). Also, there's an extra blank line at the end.

🧹 Proposed style fix
-	public function ldap() {
+	public function ldap()
+	{
 		$this->title = 'Missing PHP Extension';
 		$this->code = 500;
 		$this->message = 'The PHP extension "ldap" is required but not loaded. Please install and enable it to run Lychee.';
 		$this->displaySimpleError();
 	}
-
-

As per coding guidelines: "Run vendor/bin/php-cs-fixer fix to apply PHP code style fixes before committing."


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e40be8 and 32e7ac3.

📒 Files selected for processing (2)
  • bootstrap/PanicAttack.php
  • public/index.php

Comment on lines +21 to +28
/**
* Check if the required extensions are loaded and if not, display a nice error page.
* This is a sanity check to prevent the user from seeing a blank page with an error in the top left corner.
*/
if (!extension_loaded('ldap')) {
$panic_attack = new PanicAttack();
$panic_attack->ldap();
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

echo "=== Searching for LDAP configuration and references ==="
rg -i 'ldap' -t php --max-count=50 -n

echo ""
echo "=== Checking .env files for LDAP config ==="
find . -name ".env*" -type f -exec grep -H -i ldap {} \; 2>/dev/null || echo "No .env files with LDAP config found"

echo ""
echo "=== Checking if extension_loaded is used conditionally elsewhere ==="
rg "extension_loaded" -t php -n

echo ""
echo "=== Checking config directory structure ==="
fd "config" -t d | head -20

echo ""
echo "=== Searching for PanicAttack class to understand its usage ==="
rg "class PanicAttack" -A 20 -t php

Repository: LycheeOrg/Lychee

Length of output: 50372


🏁 Script executed:

# Quick check: Verify if there's documentation about LDAP being required
rg -i "ldap.*required\|required.*ldap" README.md docs/ 2>/dev/null | head -20 || echo "No documentation about LDAP requirement found"

Repository: LycheeOrg/Lychee

Length of output: 42


Make LDAP extension check conditional on configured usage.

The current bootstrap check at public/index.php:25-27 makes the ldap PHP extension mandatory for all Lychee installations. However, LDAP authentication is an optional feature disabled by default (config/ldap.php:52: 'enabled' => false). This inconsistency prevents users who don't use LDAP from running the application if the extension is not installed.

Either move the check to occur only when LDAP authentication is actually enabled in configuration, or remove the hard requirement and let optional features fail gracefully at runtime.

@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.37%. Comparing base (425329f) to head (32e7ac3).
⚠️ Report is 1 commits behind head on master.

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant