Skip to content

Commit a4326be

Browse files
committed
Refactor I/O exceptions
1 parent ceb459f commit a4326be

16 files changed

Lines changed: 49 additions & 42 deletions

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Web change log
33

44
## ?.?.? / ????-??-??
55

6+
## 4.10.0 / 2026-06-21
7+
8+
* Merged PR #22: Refactor I/O exceptions, dropping XP 10 support in the
9+
doing. See xp-framework/core#363 for a write-up on the reason behind
10+
this and the plan to move forward.
11+
(@thekid)
12+
613
## 4.9.0 / 2026-06-07
714

815
* Merged PR #131: Implement `web.filters.CORS` (feature requested in #128),

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description" : "Web applications for the XP Framework",
77
"keywords": ["module", "xp"],
88
"require" : {
9-
"xp-framework/core": "^12.0 | ^11.0 | ^10.0",
9+
"xp-framework/core": "^12.11 | ^11.11",
1010
"xp-framework/networking": "^11.0 | ^10.1 | ^9.3",
1111
"xp-forge/uri": "^3.0 | ^2.0 | ^1.4",
1212
"php": ">=7.0.0"

src/main/php/web/io/Incomplete.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace web\io;
22

3-
use io\OperationNotSupportedException;
3+
use io\NotSupported;
44
use io\streams\InputStream;
55
use web\io\Part;
66

@@ -42,9 +42,9 @@ public function kind() { return Part::INCOMPLETE; }
4242
/** @return string */
4343
public function error() { return $this->error; }
4444

45-
/** @return io.IOException */
45+
/** @return io.OperationFailed */
4646
private function notSupported() {
47-
return new OperationNotSupportedException('Cannot read from incomplete part (error= '.$this->error.')');
47+
return new NotSupported('Cannot read from incomplete part (error= '.$this->error.')');
4848
}
4949

5050
/** @return string */
@@ -56,7 +56,7 @@ public function bytes() { throw $this->notSupported(); }
5656
* @param io.Path|io.Folder|io.streams.OutputStream|string $target
5757
* @return iterable
5858
* @throws lang.IllegalArgumentException if filename is invalid
59-
* @throws io.IOException
59+
* @throws io.OperationFailed
6060
*/
6161
public function transmit($target) { throw $this->notSupported(); yield; }
6262

src/main/php/web/io/ReadChunks.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace web\io;
22

3-
use io\IOException;
3+
use io\OperationFailed;
44
use io\streams\InputStream;
55

66
/**
@@ -18,13 +18,13 @@ class ReadChunks implements InputStream {
1818
* Scans a chunk, populating length and buffer
1919
*
2020
* @return int
21-
* @throws io.IOException for chunked format errors
21+
* @throws io.OperationFailed for chunked format errors
2222
*/
2323
private function scan() {
2424
$size= $this->input->readLine() ?? '';
2525

2626
if (1 !== sscanf($size, '%x', $l)) {
27-
throw new IOException('No chunk segment present (`'.addcslashes($size, "\0..\37").'`)');
27+
throw new OperationFailed('No chunk segment present (`'.addcslashes($size, "\0..\37").'`)');
2828
}
2929

3030
// Chunk with 0 length indicates EOF
@@ -80,7 +80,7 @@ public function read($limit= 8192) {
8080
$chunk= substr($this->buffer, 0, min($limit, $remaining));
8181
if ('' === $chunk) {
8282
$this->remaining= 0;
83-
throw new IOException('EOF');
83+
throw new OperationFailed('EOF');
8484
}
8585

8686
$length= strlen($chunk);

src/main/php/web/io/ReadLength.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace web\io;
22

3-
use io\IOException;
3+
use io\OperationFailed;
44
use io\streams\InputStream;
55

66
/**
@@ -32,7 +32,7 @@ public function read($limit= 8192) {
3232
$chunk= $this->input->read(min($limit, $this->remaininig));
3333
if ('' === $chunk) {
3434
$this->remaininig= 0;
35-
throw new IOException('EOF');
35+
throw new OperationFailed('EOF');
3636
}
3737

3838
$this->remaininig-= strlen($chunk);

src/main/php/web/io/Stream.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function bytes() {
7575
* @param io.Path|io.Folder|io.streams.OutputStream|string $target
7676
* @return iterable
7777
* @throws lang.IllegalArgumentException if filename is invalid
78-
* @throws io.IOException
78+
* @throws io.OperationFailed
7979
*/
8080
public function transmit($target) {
8181
if ($target instanceof OutputStream) {

src/main/php/xp/web/Upload.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function bytes() {
6565
* @param io.Path|io.Folder|io.streams.OutputStream|string $target
6666
* @return iterable
6767
* @throws lang.IllegalArgumentException if filename is invalid
68-
* @throws io.IOException
68+
* @throws io.OperationFailed
6969
*/
7070
public function transmit($target) {
7171

src/main/php/xp/web/srv/CannotWrite.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php namespace xp\web\srv;
22

3-
use io\IOException;
3+
use io\OperationFailed;
44

5-
class CannotWrite extends IOException {
5+
class CannotWrite extends OperationFailed {
66

77
/** @return string */
88
public function toString(): string { return $this->message; }

src/main/php/xp/web/srv/Develop.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace xp\web\srv;
22

3-
use io\IOException;
3+
use io\OperationFailed;
44
use lang\archive\ArchiveClassLoader;
55
use lang\{ClassLoader, CommandLine, FileSystemClassLoader, Runtime, RuntimeOptions};
66
use peer\Socket;
@@ -74,7 +74,7 @@ public function serve($source, $profile, $webroot, $docroot, $config, $args, $lo
7474
$cmd= 'exec '.$cmd; // Replace launching shell with PHP
7575
}
7676
if (!($proc= proc_open($cmd, [STDIN, STDOUT, ['file', $nul, 'w']], $pipes, null, null, ['bypass_shell' => true]))) {
77-
throw new IOException('Cannot execute `'.$runtime->getExecutable()->getFileName().'`');
77+
throw new OperationFailed('Cannot execute `'.$runtime->getExecutable()->getFileName().'`');
7878
}
7979

8080
Console::writeLinef(

src/test/php/web/unittest/io/IncompleteTest.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace web\unittest\io;
22

3-
use io\OperationNotSupportedException;
3+
use io\NotSupported;
44
use test\{Assert, Expect, Test};
55
use web\io\{Incomplete, Part};
66

@@ -29,20 +29,20 @@ public function string_representation() {
2929
);
3030
}
3131

32-
#[Test, Expect(OperationNotSupportedException::class)]
32+
#[Test, Expect(NotSupported::class)]
3333
public function cannot_access_bytes() {
3434
(new Incomplete('upload', UPLOAD_ERR_INI_SIZE))->bytes();
3535
}
3636

37-
#[Test, Expect(OperationNotSupportedException::class)]
37+
#[Test, Expect(NotSupported::class)]
3838
public function cannot_transmit() {
3939
$it= (new Incomplete('upload', UPLOAD_ERR_INI_SIZE))->transmit('./uploads');
4040
while ($it->valid()) {
4141
$it->next();
4242
}
4343
}
4444

45-
#[Test, Expect(OperationNotSupportedException::class)]
45+
#[Test, Expect(NotSupported::class)]
4646
public function cannot_read_bytes() {
4747
(new Incomplete('upload', UPLOAD_ERR_INI_SIZE))->read();
4848
}

0 commit comments

Comments
 (0)