Skip to content

Convert more zlib warnings to exceptions #12708

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

Closed
wants to merge 1 commit into from

Conversation

bor0
Copy link
Contributor

@bor0 bor0 commented Nov 17, 2023

This PR further extends the functionality of a previous PR #4985.

Ran into this while working on a particular WordPress functionality - our servers reported tons of warnings. Currently, the only way to avoid warnings is to call @gzinflate, but silencing errors is discouraged so we also have to phpcs:ignore it. If gzinflate threw an exception instead, it would be much easier for developers to handle this.

Applied same reasoning to all the zlib functions.

I also found out that the json extension also does not use any notices:

bor0:~/dev/php-src/ext/json$ grep -R php_error_docref *
bor0:~/dev/php-src/ext/json$

⚠️This is a breaking change and may cause code flow interruptions unless handled with exceptions⚠️

@bor0
Copy link
Contributor Author

bor0 commented Nov 17, 2023

cc @Girgias @nikic for visibility, who reviewed the previous PR.

@bor0 bor0 force-pushed the zlib-warnings-to-exceptions branch 2 times, most recently from 4daa282 to 539d7b0 Compare November 17, 2023 20:16
@bor0 bor0 requested a review from bukka as a code owner November 17, 2023 20:16
This PR further extends the functionality of a previous PR #4985.

Ran into this while working on a [particular WordPress functionality](Automattic/jetpack#34186) - our servers reported tons of warnings. Currently, the only way to avoid warnings is to call `@gzinflate`, but silencing errors is discouraged so we also have to `phpcs:ignore` it. If `gzinflate` threw an exception instead, it would be much easier for developers to handle this.

Applied same reasoning to all the zlib functions.

I also found out that the `json` extension also does not use any notices:

```
bor0:~/dev/php-src/ext/json$ grep -R php_error_docref *
bor0:~/dev/php-src/ext/json$
```

⚠️This is a breaking change and may cause code flow interruptions unless handled with exceptions⚠️
@bor0 bor0 force-pushed the zlib-warnings-to-exceptions branch from 539d7b0 to 0965193 Compare November 17, 2023 20:57
@Girgias
Copy link
Member

Girgias commented Nov 18, 2023

The implicit policy is that we don't use exceptions/errors for states that cannot be programmatically checked in advance.

As such, I don't think we can do this. The BC break especially feels like this requires an RFC.

@bor0
Copy link
Contributor Author

bor0 commented Nov 20, 2023

@Girgias, thanks for your comment.

The implicit policy is that we don't use exceptions/errors for states that cannot be programmatically checked in advance.

So if we strictly follow this policy (which isn't necessarily followed for other extensions across), does that mean silencing function calls is the preferred way to do it properly?

As such, I don't think we can do this. The BC break especially feels like this requires an RFC.

I am okay to file an RFC for this, maybe after I get more comments about what people think of this PR in general.

Just a note, #4985 created similar backwards incompatibility - curious if it had (or if it was necessary to have) an RFC?

@Girgias
Copy link
Member

Girgias commented Nov 20, 2023

@Girgias, thanks for your comment.

Just a note, #4985 created similar backwards incompatibility - curious if it had (or if it was necessary to have) an RFC?

The errors introduced in that PR are things that you can check in advance are always valid, such as the compression argument being in a valid range or that one uses one of the ZLIB constants, i.e. programming errors.

The warnings you are trying to promote are warnings that are emitted by the C library, and cannot be checked in advance as they depend on the archive.

@bor0 bor0 closed this Dec 6, 2023
@bor0 bor0 deleted the zlib-warnings-to-exceptions branch December 6, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants