Skip to content

Commit 31f91e5

Browse files
committed
stream: use StreamError class constants for codes
1 parent c1cda21 commit 31f91e5

11 files changed

+887
-325
lines changed

ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Directory
1717
RoundingMode
1818
StreamBucket
1919
StreamError
20-
StreamErrorCode
2120
StreamErrorMode
2221
StreamErrorStore
2322
StreamException

ext/standard/tests/streams/stream_errors_error_code_helpers.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Stream errors - StreamErrorCode helper methods
2+
Stream errors - StreamError helper methods
33
--FILE--
44
<?php
55

@@ -14,10 +14,10 @@ $stream = fopen('php://nonexistent', 'r', false, $context);
1414

1515
$error = stream_get_last_error();
1616
if ($error) {
17-
echo "Is I/O error: " . ($error->code->isIoError() ? 'yes' : 'no') . "\n";
18-
echo "Is filesystem error: " . ($error->code->isFileSystemError() ? 'yes' : 'no') . "\n";
19-
echo "Is network error: " . ($error->code->isNetworkError() ? 'yes' : 'no') . "\n";
20-
echo "Is wrapper error: " . ($error->code->isWrapperError() ? 'yes' : 'no') . "\n";
17+
echo "Is I/O error: " . ($error->isIoError() ? 'yes' : 'no') . "\n";
18+
echo "Is filesystem error: " . ($error->isFileSystemError() ? 'yes' : 'no') . "\n";
19+
echo "Is network error: " . ($error->isNetworkError() ? 'yes' : 'no') . "\n";
20+
echo "Is wrapper error: " . ($error->isWrapperError() ? 'yes' : 'no') . "\n";
2121
}
2222

2323
?>

ext/standard/tests/streams/stream_errors_exception_mode_terminal.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ try {
1818
$error = $e->getError();
1919
if ($error) {
2020
echo "Wrapper: " . $error->wrapperName . "\n";
21-
echo "Error code name: " . $error->code->name . "\n";
2221
}
2322
}
2423

@@ -27,4 +26,3 @@ try {
2726
Caught: Failed to open stream: operation failed
2827
Code: 36
2928
Wrapper: PHP
30-
Error code name: OpenFailed

ext/standard/tests/streams/stream_errors_mix_modes_storage.phpt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function stream_test_errors($title, $context) {
4747
if ($error) {
4848
echo "Error details:\n";
4949
echo "- Message: " . $error->message . "\n";
50-
echo "- Code: " . $error->code->name . " (" . $error->code->value . ")\n";
50+
echo "- Code: $error->code\n";
5151
echo "- Wrapper: " . $error->wrapperName . "\n";
5252
echo "- Terminating: " . ($error->terminating ? 'yes' : 'no') . "\n";
5353
echo "- Count: " . $error->count() . "\n";
@@ -56,7 +56,7 @@ function stream_test_errors($title, $context) {
5656
$current = $error;
5757
$idx = 0;
5858
while ($current) {
59-
echo " [$idx] " . $current->code->name . ": " . $current->message . "\n";
59+
echo " [$idx] " . $current->code . ": " . $current->message . "\n";
6060
$current = $current->next;
6161
$idx++;
6262
}
@@ -106,41 +106,41 @@ stream_test_errors('AUTO ERROR', [
106106
ALL
107107
Error details:
108108
- Message: TestStream::stream_cast is not implemented!
109-
- Code: NotImplemented (70)
109+
- Code: 70
110110
- Wrapper: user-space
111111
- Terminating: yes
112112
- Count: 2
113-
[0] NotImplemented: TestStream::stream_cast is not implemented!
114-
[1] CastNotSupported: Cannot represent a stream of type user-space as a select()able descriptor
113+
[0] 70: TestStream::stream_cast is not implemented!
114+
[1] 101: Cannot represent a stream of type user-space as a select()able descriptor
115115

116116
NON TERMINATING
117117
Error details:
118118
- Message: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
119-
- Code: UserspaceInvalidReturn (161)
119+
- Code: 161
120120
- Wrapper: user-space
121121
- Terminating: no
122122
- Count: 1
123-
[0] UserspaceInvalidReturn: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
123+
[0] 161: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
124124

125125
TERMINATING
126126
Error details:
127127
- Message: TestStream::stream_cast is not implemented!
128-
- Code: NotImplemented (70)
128+
- Code: 70
129129
- Wrapper: user-space
130130
- Terminating: yes
131131
- Count: 2
132-
[0] NotImplemented: TestStream::stream_cast is not implemented!
133-
[1] CastNotSupported: Cannot represent a stream of type user-space as a select()able descriptor
132+
[0] 70: TestStream::stream_cast is not implemented!
133+
[1] 101: Cannot represent a stream of type user-space as a select()able descriptor
134134

135135
AUTO EXCEPTION
136136
EXCEPTION: TestStream::stream_cast is not implemented!
137137
Error details:
138138
- Message: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
139-
- Code: UserspaceInvalidReturn (161)
139+
- Code: 161
140140
- Wrapper: user-space
141141
- Terminating: no
142142
- Count: 1
143-
[0] UserspaceInvalidReturn: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
143+
[0] 161: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
144144

145145
AUTO ERROR
146146

@@ -151,8 +151,8 @@ Warning: stream_select(): TestStream::stream_cast is not implemented! in %s on l
151151
Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s on line %d
152152
Error details:
153153
- Message: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
154-
- Code: UserspaceInvalidReturn (161)
154+
- Code: 161
155155
- Wrapper: user-space
156156
- Terminating: no
157157
- Count: 1
158-
[0] UserspaceInvalidReturn: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost
158+
[0] 161: TestStream::stream_read - read 10 bytes more data than requested (8202 read, 8192 max) - excess data will be lost

ext/standard/tests/streams/stream_errors_multi_store.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ $stream = fopen('php://nonexistent', 'r', false, $context);
1313

1414
$error = stream_get_last_error();
1515
if ($error) {
16-
echo "Has OpenFailed: " . ($error->hasCode(StreamErrorCode::OpenFailed) ? 'yes' : 'no') . "\n";
17-
echo "Has NotFound: " . ($error->hasCode(StreamErrorCode::NotFound) ? 'yes' : 'no') . "\n";
16+
echo "Has OpenFailed: " . ($error->hasCode(StreamError::CODE_OPEN_FAILED) ? 'yes' : 'no') . "\n";
17+
echo "Has NotFound: " . ($error->hasCode(StreamError::CODE_NOT_FOUND) ? 'yes' : 'no') . "\n";
1818
}
1919

2020
?>

ext/standard/tests/streams/stream_errors_silent_with_handler.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $context = stream_context_create([
1212
$handler_called = true;
1313
echo "Handler called\n";
1414
echo "Wrapper: " . $error->wrapperName . "\n";
15-
echo "Code: " . $error->code->name . "\n";
15+
echo "Code: " . $error->code . "\n";
1616
echo "Message: " . $error->message . "\n";
1717
echo "Param: " . ($error->param ?? 'null') . "\n";
1818
echo "Terminating: " . ($error->terminating ? 'yes' : 'no') . "\n";
@@ -28,7 +28,7 @@ var_dump($handler_called);
2828
--EXPECT--
2929
Handler called
3030
Wrapper: PHP
31-
Code: OpenFailed
31+
Code: 36
3232
Message: Failed to open stream: operation failed
3333
Param: php://nonexistent
3434
Terminating: yes

ext/standard/tests/streams/stream_errors_silent_with_storage.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var_dump($stream);
1515
$error = stream_get_last_error();
1616
if ($error) {
1717
echo "Has error: yes\n";
18-
echo "Error code: " . $error->code->name . "\n";
18+
echo "Error code: " . $error->code . "\n";
1919
echo "Error wrapper: " . $error->wrapperName . "\n";
2020
echo "Error message: " . $error->message . "\n";
2121
}
@@ -24,6 +24,6 @@ if ($error) {
2424
--EXPECT--
2525
bool(false)
2626
Has error: yes
27-
Error code: OpenFailed
27+
Error code: 36
2828
Error wrapper: PHP
2929
Error message: Failed to open stream: operation failed

main/streams/php_stream_errors.h

Lines changed: 89 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -61,102 +61,94 @@ BEGIN_EXTERN_C()
6161
#define STREAM_ERROR_CODE_USERSPACE_START 160
6262
#define STREAM_ERROR_CODE_USERSPACE_END 170
6363

64-
/* X-macro defining all error codes */
65-
#define PHP_STREAM_ERROR_CODES(V) \
66-
/* General errors */ \
67-
V(NONE, None, 0) \
68-
V(GENERIC, Generic, 1) \
69-
/* I/O operation errors (10-29) */ \
70-
V(READ_FAILED, ReadFailed, 10) \
71-
V(WRITE_FAILED, WriteFailed, 11) \
72-
V(SEEK_FAILED, SeekFailed, 12) \
73-
V(SEEK_NOT_SUPPORTED, SeekNotSupported, 13) \
74-
V(FLUSH_FAILED, FlushFailed, 14) \
75-
V(TRUNCATE_FAILED, TruncateFailed, 15) \
76-
V(CONNECT_FAILED, ConnectFailed, 16) \
77-
V(BIND_FAILED, BindFailed, 17) \
78-
V(LISTEN_FAILED, ListenFailed, 18) \
79-
V(NOT_WRITABLE, NotWritable, 19) \
80-
V(NOT_READABLE, NotReadable, 20) \
81-
/* File system operations (30-69) */ \
82-
V(DISABLED, Disabled, 30) \
83-
V(NOT_FOUND, NotFound, 31) \
84-
V(PERMISSION_DENIED, PermissionDenied, 32) \
85-
V(ALREADY_EXISTS, AlreadyExists, 33) \
86-
V(INVALID_PATH, InvalidPath, 34) \
87-
V(PATH_TOO_LONG, PathTooLong, 35) \
88-
V(OPEN_FAILED, OpenFailed, 36) \
89-
V(CREATE_FAILED, CreateFailed, 37) \
90-
V(DUP_FAILED, DupFailed, 38) \
91-
V(UNLINK_FAILED, UnlinkFailed, 39) \
92-
V(RENAME_FAILED, RenameFailed, 40) \
93-
V(MKDIR_FAILED, MkdirFailed, 41) \
94-
V(RMDIR_FAILED, RmdirFailed, 42) \
95-
V(STAT_FAILED, StatFailed, 43) \
96-
V(META_FAILED, MetaFailed, 44) \
97-
V(CHMOD_FAILED, ChmodFailed, 45) \
98-
V(CHOWN_FAILED, ChownFailed, 46) \
99-
V(COPY_FAILED, CopyFailed, 47) \
100-
V(TOUCH_FAILED, TouchFailed, 48) \
101-
V(INVALID_MODE, InvalidMode, 49) \
102-
V(INVALID_META, InvalidMeta, 50) \
103-
V(MODE_NOT_SUPPORTED, ModeNotSupported, 51) \
104-
V(READONLY, Readonly, 52) \
105-
V(RECURSION_DETECTED, RecursionDetected, 53) \
106-
/* Wrapper/protocol operations (70-89) */ \
107-
V(NOT_IMPLEMENTED, NotImplemented, 70) \
108-
V(NO_OPENER, NoOpener, 71) \
109-
V(PERSISTENT_NOT_SUPPORTED, PersistentNotSupported, 72) \
110-
V(WRAPPER_NOT_FOUND, WrapperNotFound, 73) \
111-
V(WRAPPER_DISABLED, WrapperDisabled, 74) \
112-
V(PROTOCOL_UNSUPPORTED, ProtocolUnsupported, 75) \
113-
V(WRAPPER_REGISTRATION_FAILED, WrapperRegistrationFailed, 76) \
114-
V(WRAPPER_UNREGISTRATION_FAILED, WrapperUnregistrationFailed, 77) \
115-
V(WRAPPER_RESTORATION_FAILED, WrapperRestorationFailed, 78) \
116-
/* Filter operations (90-99) */ \
117-
V(FILTER_NOT_FOUND, FilterNotFound, 90) \
118-
V(FILTER_FAILED, FilterFailed, 91) \
119-
/* Cast/conversion operations (100-109) */ \
120-
V(CAST_FAILED, CastFailed, 100) \
121-
V(CAST_NOT_SUPPORTED, CastNotSupported, 101) \
122-
V(MAKE_SEEKABLE_FAILED, MakeSeekableFailed, 102) \
123-
V(BUFFERED_DATA_LOST, BufferedDataLost, 103) \
124-
/* Network/socket operations (110-129) */ \
125-
V(NETWORK_SEND_FAILED, NetworkSendFailed, 110) \
126-
V(NETWORK_RECV_FAILED, NetworkRecvFailed, 111) \
127-
V(SSL_NOT_SUPPORTED, SslNotSupported, 112) \
128-
V(RESUMPTION_FAILED, ResumptionFailed, 113) \
129-
V(SOCKET_PATH_TOO_LONG, SocketPathTooLong, 114) \
130-
V(OOB_NOT_SUPPORTED, OobNotSupported, 115) \
131-
V(PROTOCOL_ERROR, ProtocolError, 116) \
132-
V(INVALID_URL, InvalidUrl, 117) \
133-
V(INVALID_RESPONSE, InvalidResponse, 118) \
134-
V(INVALID_HEADER, InvalidHeader, 119) \
135-
V(INVALID_PARAM, InvalidParam, 120) \
136-
V(REDIRECT_LIMIT, RedirectLimit, 121) \
137-
V(AUTH_FAILED, AuthFailed, 122) \
138-
/* Encoding/decoding/archiving operations (130-139) */ \
139-
V(ARCHIVING_FAILED, ArchivingFailed, 130) \
140-
V(ENCODING_FAILED, EncodingFailed, 131) \
141-
V(DECODING_FAILED, DecodingFailed, 132) \
142-
V(INVALID_FORMAT, InvalidFormat, 133) \
143-
/* Resource/allocation operations (140-149) */ \
144-
V(ALLOCATION_FAILED, AllocationFailed, 140) \
145-
V(TEMPORARY_FILE_FAILED, TemporaryFileFailed, 141) \
146-
/* Locking operations (150-159) */ \
147-
V(LOCK_FAILED, LockFailed, 150) \
148-
V(LOCK_NOT_SUPPORTED, LockNotSupported, 151) \
149-
/* Userspace stream operations (160-169) */ \
150-
V(USERSPACE_NOT_IMPLEMENTED, UserspaceNotImplemented, 160) \
151-
V(USERSPACE_INVALID_RETURN, UserspaceInvalidReturn, 161) \
152-
V(USERSPACE_CALL_FAILED, UserspaceCallFailed, 162)
153-
154-
/* Generate C enum for internal use */
155-
typedef enum _StreamErrorCode {
156-
#define V(uc_name, name, val) STREAM_ERROR_CODE_##uc_name = val,
157-
PHP_STREAM_ERROR_CODES(V)
158-
#undef V
159-
} StreamErrorCode;
64+
/* Error codes - exposed as StreamError::ERROR_CODE_* class constants */
65+
/* General errors */
66+
#define STREAM_ERROR_CODE_NONE 0
67+
#define STREAM_ERROR_CODE_GENERIC 1
68+
/* I/O operation errors (10-29) */
69+
#define STREAM_ERROR_CODE_READ_FAILED 10
70+
#define STREAM_ERROR_CODE_WRITE_FAILED 11
71+
#define STREAM_ERROR_CODE_SEEK_FAILED 12
72+
#define STREAM_ERROR_CODE_SEEK_NOT_SUPPORTED 13
73+
#define STREAM_ERROR_CODE_FLUSH_FAILED 14
74+
#define STREAM_ERROR_CODE_TRUNCATE_FAILED 15
75+
#define STREAM_ERROR_CODE_CONNECT_FAILED 16
76+
#define STREAM_ERROR_CODE_BIND_FAILED 17
77+
#define STREAM_ERROR_CODE_LISTEN_FAILED 18
78+
#define STREAM_ERROR_CODE_NOT_WRITABLE 19
79+
#define STREAM_ERROR_CODE_NOT_READABLE 20
80+
/* File system operations (30-69) */
81+
#define STREAM_ERROR_CODE_DISABLED 30
82+
#define STREAM_ERROR_CODE_NOT_FOUND 31
83+
#define STREAM_ERROR_CODE_PERMISSION_DENIED 32
84+
#define STREAM_ERROR_CODE_ALREADY_EXISTS 33
85+
#define STREAM_ERROR_CODE_INVALID_PATH 34
86+
#define STREAM_ERROR_CODE_PATH_TOO_LONG 35
87+
#define STREAM_ERROR_CODE_OPEN_FAILED 36
88+
#define STREAM_ERROR_CODE_CREATE_FAILED 37
89+
#define STREAM_ERROR_CODE_DUP_FAILED 38
90+
#define STREAM_ERROR_CODE_UNLINK_FAILED 39
91+
#define STREAM_ERROR_CODE_RENAME_FAILED 40
92+
#define STREAM_ERROR_CODE_MKDIR_FAILED 41
93+
#define STREAM_ERROR_CODE_RMDIR_FAILED 42
94+
#define STREAM_ERROR_CODE_STAT_FAILED 43
95+
#define STREAM_ERROR_CODE_META_FAILED 44
96+
#define STREAM_ERROR_CODE_CHMOD_FAILED 45
97+
#define STREAM_ERROR_CODE_CHOWN_FAILED 46
98+
#define STREAM_ERROR_CODE_COPY_FAILED 47
99+
#define STREAM_ERROR_CODE_TOUCH_FAILED 48
100+
#define STREAM_ERROR_CODE_INVALID_MODE 49
101+
#define STREAM_ERROR_CODE_INVALID_META 50
102+
#define STREAM_ERROR_CODE_MODE_NOT_SUPPORTED 51
103+
#define STREAM_ERROR_CODE_READONLY 52
104+
#define STREAM_ERROR_CODE_RECURSION_DETECTED 53
105+
/* Wrapper/protocol operations (70-89) */
106+
#define STREAM_ERROR_CODE_NOT_IMPLEMENTED 70
107+
#define STREAM_ERROR_CODE_NO_OPENER 71
108+
#define STREAM_ERROR_CODE_PERSISTENT_NOT_SUPPORTED 72
109+
#define STREAM_ERROR_CODE_WRAPPER_NOT_FOUND 73
110+
#define STREAM_ERROR_CODE_WRAPPER_DISABLED 74
111+
#define STREAM_ERROR_CODE_PROTOCOL_UNSUPPORTED 75
112+
#define STREAM_ERROR_CODE_WRAPPER_REGISTRATION_FAILED 76
113+
#define STREAM_ERROR_CODE_WRAPPER_UNREGISTRATION_FAILED 77
114+
#define STREAM_ERROR_CODE_WRAPPER_RESTORATION_FAILED 78
115+
/* Filter operations (90-99) */
116+
#define STREAM_ERROR_CODE_FILTER_NOT_FOUND 90
117+
#define STREAM_ERROR_CODE_FILTER_FAILED 91
118+
/* Cast/conversion operations (100-109) */
119+
#define STREAM_ERROR_CODE_CAST_FAILED 100
120+
#define STREAM_ERROR_CODE_CAST_NOT_SUPPORTED 101
121+
#define STREAM_ERROR_CODE_MAKE_SEEKABLE_FAILED 102
122+
#define STREAM_ERROR_CODE_BUFFERED_DATA_LOST 103
123+
/* Network/socket operations (110-129) */
124+
#define STREAM_ERROR_CODE_NETWORK_SEND_FAILED 110
125+
#define STREAM_ERROR_CODE_NETWORK_RECV_FAILED 111
126+
#define STREAM_ERROR_CODE_SSL_NOT_SUPPORTED 112
127+
#define STREAM_ERROR_CODE_RESUMPTION_FAILED 113
128+
#define STREAM_ERROR_CODE_SOCKET_PATH_TOO_LONG 114
129+
#define STREAM_ERROR_CODE_OOB_NOT_SUPPORTED 115
130+
#define STREAM_ERROR_CODE_PROTOCOL_ERROR 116
131+
#define STREAM_ERROR_CODE_INVALID_URL 117
132+
#define STREAM_ERROR_CODE_INVALID_RESPONSE 118
133+
#define STREAM_ERROR_CODE_INVALID_HEADER 119
134+
#define STREAM_ERROR_CODE_INVALID_PARAM 120
135+
#define STREAM_ERROR_CODE_REDIRECT_LIMIT 121
136+
#define STREAM_ERROR_CODE_AUTH_FAILED 122
137+
/* Encoding/decoding/archiving operations (130-139) */
138+
#define STREAM_ERROR_CODE_ARCHIVING_FAILED 130
139+
#define STREAM_ERROR_CODE_ENCODING_FAILED 131
140+
#define STREAM_ERROR_CODE_DECODING_FAILED 132
141+
#define STREAM_ERROR_CODE_INVALID_FORMAT 133
142+
/* Resource/allocation operations (140-149) */
143+
#define STREAM_ERROR_CODE_ALLOCATION_FAILED 140
144+
#define STREAM_ERROR_CODE_TEMPORARY_FILE_FAILED 141
145+
/* Locking operations (150-159) */
146+
#define STREAM_ERROR_CODE_LOCK_FAILED 150
147+
#define STREAM_ERROR_CODE_LOCK_NOT_SUPPORTED 151
148+
/* Userspace stream operations (160-169) */
149+
#define STREAM_ERROR_CODE_USERSPACE_NOT_IMPLEMENTED 160
150+
#define STREAM_ERROR_CODE_USERSPACE_INVALID_RETURN 161
151+
#define STREAM_ERROR_CODE_USERSPACE_CALL_FAILED 162
160152

161153
/* Wrapper name for PHP errors */
162154
#define PHP_STREAM_ERROR_WRAPPER_DEFAULT_NAME ":na"
@@ -166,7 +158,7 @@ typedef enum _StreamErrorCode {
166158
/* Error entry in chain */
167159
typedef struct _php_stream_error_entry {
168160
zend_string *message;
169-
StreamErrorCode code;
161+
int code;
170162
char *wrapper_name;
171163
char *param;
172164
char *docref;

0 commit comments

Comments
 (0)