Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): Suppress config.php fopen error at install time #48426

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Sep 27, 2024

Summary

The changes in #44230 brought back a regression from the OC days which is generating a non-operational error immediately after install time:

owncloud/core#13736
owncloud/core#21923

{"reqId":"58mbKNITzcU0stL3faUH","level":3,"time":"2024-09-26T19:52:18+00:00","remoteAddr":"","user":"ncadmin","app":"PHP","method":"","url":"--","message":"fopen(/var/www/html/config/config.php): Failed to open stream: No such file or directory at /var/www/html/lib/private/Config.php#190","userAgent":"--","version":"30.0.0.14","data":{"app":"PHP"},"id":"66f5bc6a0d035"}

It becomes the very first log entry you see after a new install. While harmless from a technical standpoint, it is needless to say, not a great way for someone to be introduced to Nextcloud right after installation. And it gives the impression something is wrong, when it really isn't.

Cause

At install time we use our onError error handler:

set_error_handler([$errorHandler, 'onError']);

This handler lacks handling to exclude suppressors:

public function onError(int $number, string $message, string $file, int $line): bool {
if (!(error_reporting() & $number)) {
return true;
}
$msg = $message . ' at ' . $file . '#' . $line;
$e = new Error(self::removePassword($msg));
$this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']);
return true;
}

The easiest solution is simply to add back the file_exists() check here before we call fopen().

Additional thoughts

Despite this PR, I was tempted to add support in the onError handler for the suppressor. That way things behave in a standard way. If we want to suppress, it's been decided upon for a good reason. I took the approach here in this PR for now though because it seemed more conservative, by simply bringing back the file_exists() check and relying on that instead of the non-functioning suppressor. This PR should be sufficient though since there aren't currently any other known situations where the suppressor handling is an issue. If/when other spots with the suppressor pop up, we could reconsider.

TODO

Checklist

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards added bug 3. to review Waiting for reviews feature: install and update php Pull requests that update Php code labels Sep 27, 2024
@joshtrichards
Copy link
Member Author

/backport to stable30

@joshtrichards
Copy link
Member Author

/backport to stable29

@joshtrichards
Copy link
Member Author

/backport to stable28

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

Either that or supporting the suppressor in onError is fine for me.
It’s really a pain that php fopen works like this -_-

@joshtrichards joshtrichards marked this pull request as ready for review September 30, 2024 22:11
@joshtrichards joshtrichards added this to the Nextcloud 31 milestone Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug feature: install and update php Pull requests that update Php code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Failed to open stream + Error while running background job immediately after installation
3 participants