Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/php/web/io/Incomplete.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\io;

use io\OperationNotSupportedException;
use io\NotSupported;
use io\streams\InputStream;
use web\io\Part;

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/main/php/web/io/ReadChunks.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\io;

use io\IOException;
use io\OperationFailed;
use io\streams\InputStream;

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

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

// Chunk with 0 length indicates EOF
Expand Down Expand Up @@ -81,7 +81,7 @@ public function read($limit= 8192) {
$chunk= substr($this->buffer, 0, min($limit, $remaining));
if ('' === $chunk) {
$this->remaining= 0;
throw new IOException('Unexpected EOF');
throw new OperationFailed('Unexpected EOF');
}

$length= strlen($chunk);
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/web/io/ReadLength.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\io;

use io\IOException;
use io\OperationFailed;
use io\streams\InputStream;

/**
Expand Down Expand Up @@ -34,7 +34,7 @@ public function read($limit= 8192) {
$chunk= $this->input->read(min($limit, $this->remaininig));
if ('' === $chunk) {
$this->remaininig= 0;
throw new IOException('EOF');
throw new OperationFailed('EOF');
}

$this->remaininig-= strlen($chunk);
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/web/io/Stream.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function bytes() {
* @param io.Path|io.Folder|io.streams.OutputStream|string $target
* @return iterable
* @throws lang.IllegalArgumentException if filename is invalid
* @throws io.IOException
* @throws io.OperationFailed
*/
public function transmit($target) {
if ($target instanceof OutputStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/web/Upload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function bytes() {
* @param io.Path|io.Folder|io.streams.OutputStream|string $target
* @return iterable
* @throws lang.IllegalArgumentException if filename is invalid
* @throws io.IOException
* @throws io.OperationFailed
*/
public function transmit($target) {

Expand Down
4 changes: 2 additions & 2 deletions src/main/php/xp/web/srv/CannotWrite.class.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace xp\web\srv;

use io\IOException;
use io\OperationFailed;

class CannotWrite extends IOException {
class CannotWrite extends OperationFailed {

/** @return string */
public function toString(): string { return $this->message; }
Expand Down
8 changes: 4 additions & 4 deletions src/main/php/xp/web/srv/Workers.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace xp\web\srv;

use io\{Path, IOException};
use io\{Path, OperationFailed};
use lang\archive\ArchiveClassLoader;
use lang\{Runtime, RuntimeOptions, CommandLine, FileSystemClassLoader};
use peer\Socket;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function __construct($docroot, $classLoaders) {
/**
* Launches a worker and returns it.
*
* @throws io.IOException
* @throws io.OperationFailed
* @return xp.web.srv.Worker
*/
public function launch() {
Expand All @@ -65,7 +65,7 @@ public function launch() {
if ('WINDOWS' !== $os->name()) $commandLine= 'exec '.$commandLine;

if (!($proc= proc_open($commandLine, [STDIN, STDOUT, ['pipe', 'w']], $pipes, null, null, ['bypass_shell' => true]))) {
throw new IOException('Cannot execute `'.$commandLine.'`');
throw new OperationFailed('Cannot execute `'.$commandLine.'`');
}

// Parse `[...] PHP 8.3.15 Development Server (http://127.0.0.1:60922) started`
Expand All @@ -78,7 +78,7 @@ public function launch() {
if (!preg_match('/\([a-z]+:\/\/([0-9.]+):([0-9]+)\)/', $line, $matches)) {
proc_terminate($proc, 2);
proc_close($proc);
throw new IOException('Cannot determine bound port: `'.implode('', $lines).'`');
throw new OperationFailed('Cannot determine bound port: `'.implode('', $lines).'`');
}

return new Worker($proc, new Socket($matches[1], (int)$matches[2]));
Expand Down
8 changes: 4 additions & 4 deletions src/test/php/web/unittest/io/IncompleteTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\io;

use io\OperationNotSupportedException;
use io\NotSupported;
use test\{Assert, Expect, Test};
use web\io\{Incomplete, Part};

Expand Down Expand Up @@ -29,20 +29,20 @@ public function string_representation() {
);
}

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

#[Test, Expect(OperationNotSupportedException::class)]
#[Test, Expect(NotSupported::class)]
public function cannot_transmit() {
$it= (new Incomplete('upload', UPLOAD_ERR_INI_SIZE))->transmit('./uploads');
while ($it->valid()) {
$it->next();
}
}

#[Test, Expect(OperationNotSupportedException::class)]
#[Test, Expect(NotSupported::class)]
public function cannot_read_bytes() {
(new Incomplete('upload', UPLOAD_ERR_INI_SIZE))->read();
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/php/web/unittest/io/PartsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\io;

use io\OperationNotSupportedException;
use io\NotSupported;
use io\streams\{InputStream, MemoryInputStream, Streams};
use lang\FormatException;
use test\{Assert, Expect, Test, Values};
Expand Down Expand Up @@ -213,7 +213,7 @@ public function can_skip_reading_parts() {
Assert::equals('...', $bytes);
}

#[Test, Expect(OperationNotSupportedException::class)]
#[Test, Expect(NotSupported::class)]
public function cannot_read_from_incomplete_file() {
$parts= $this->parts(
'--%1$s',
Expand Down
8 changes: 4 additions & 4 deletions src/test/php/web/unittest/io/ReadChunksTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\io;

use io\IOException;
use io\OperationFailed;
use test\{Assert, Expect, Test, Values};
use web\io\{ReadChunks, TestInput};
use web\unittest\Chunking;
Expand All @@ -23,13 +23,13 @@ public function can_create() {
new ReadChunks($this->input("0\r\n\r\n"));
}

#[Test, Expect(IOException::class)]
#[Test, Expect(OperationFailed::class)]
public function raises_exception_from_read_when_non_chunked_data_appears() {
$fixture= new ReadChunks($this->input(''));
$fixture->read();
}

#[Test, Expect(IOException::class)]
#[Test, Expect(OperationFailed::class)]
public function raises_exception_from_available_when_non_chunked_data_appears() {
$fixture= new ReadChunks($this->input(''));
$fixture->available();
Expand Down Expand Up @@ -130,7 +130,7 @@ public function raises_exception_on_eof_in_the_middle_of_data() {
$fixture= new ReadChunks($this->input("ff\r\n...💣"));
$fixture->read();

Assert::throws(IOException::class, fn() => $fixture->read(1));
Assert::throws(OperationFailed::class, fn() => $fixture->read(1));
}

#[Test, Values([4, 8192])]
Expand Down
4 changes: 2 additions & 2 deletions src/test/php/web/unittest/io/ReadLengthTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\io;

use io\IOException;
use io\OperationFailed;
use test\{Assert, Test, Values};
use web\io\{ReadLength, TestInput};

Expand Down Expand Up @@ -51,7 +51,7 @@ public function raises_exception_on_eof_before_length_reached() {
$fixture= new ReadLength($this->input('Test'), 10);
$fixture->read();

Assert::throws(IOException::class, fn() => $fixture->read(1));
Assert::throws(OperationFailed::class, fn() => $fixture->read(1));
}

#[Test, Values([4, 8192])]
Expand Down
6 changes: 3 additions & 3 deletions src/test/php/web/unittest/io/StreamTest.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace web\unittest\io;

use io\streams\{MemoryOutputStream, Streams};
use io\{File, Files, Folder, IOException, Path};
use io\{File, Files, Folder, OperationFailed, Path};
use lang\{Environment, IllegalArgumentException};
use test\{Assert, Expect, Test, Values};
use web\io\{Part, Stream};
Expand Down Expand Up @@ -155,10 +155,10 @@ public function transmit_to_outputstream($chunks, $expected) {
Assert::equals($expected, $out->bytes());
}

#[Test, Expect(IOException::class)]
#[Test, Expect(OperationFailed::class)]
public function exceptions_raised_while_storing() {
$out= new class() extends MemoryOutputStream {
public function write($bytes) { throw new IOException('Disk full'); }
public function write($bytes) { throw new OperationFailed('Disk full'); }
};
$it= $this->newFixture(self::NAME, 'Test')->transmit($out);
while ($it->valid()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\server;

use io\IOException;
use io\OperationFailed;
use test\{Assert, Test};
use web\unittest\Channel;
use xp\web\srv\{ForwardRequests, Worker};
Expand Down Expand Up @@ -145,13 +145,13 @@ public function backend_socket_closed_on_errors() {
);
$client= new class([$request]) extends Channel {
public function write($chunk) {
throw new IOException('Test');
throw new OperationFailed('Test');
}
};
$backend= new Channel([$response]);
try {
$this->forward($client, $backend);
} catch (IOException $expected) {
} catch (OperationFailed $expected) {
// ...
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/php/web/unittest/server/SAPITest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\server;

use io\OperationNotSupportedException;
use io\NotSupported;
use io\streams\{MemoryInputStream, Streams};
use lang\IllegalStateException;
use test\{Assert, Expect, Test, Values};
Expand Down Expand Up @@ -197,13 +197,13 @@ function($part) { return $part->toString(); },
));
}

#[Test, Expect(OperationNotSupportedException::class)]
#[Test, Expect(NotSupported::class)]
public function read_from_incomplete_upload() {
$parts= $this->parts($this->incomplete('test.txt', UPLOAD_ERR_PARTIAL));
$parts['file']->bytes();
}

#[Test, Expect(OperationNotSupportedException::class)]
#[Test, Expect(NotSupported::class)]
public function stream_incomplete_upload() {
$parts= $this->parts($this->incomplete('test.txt', UPLOAD_ERR_PARTIAL));
Streams::readAll($parts['file']);
Expand Down
6 changes: 3 additions & 3 deletions src/test/php/web/unittest/server/UploadTest.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace web\unittest\server;

use io\streams\{MemoryInputStream, MemoryOutputStream, Streams};
use io\{File, Files, Folder, IOException, Path, TempFile};
use io\{File, Files, Folder, OperationFailed, Path, TempFile};
use lang\{Environment, IllegalArgumentException};
use test\{Assert, Expect, Test, Values};
use web\io\Part;
Expand Down Expand Up @@ -117,11 +117,11 @@ public function transmit_to_outputstream() {
Assert::equals('Test', $out->bytes());
}

#[Test, Expect(IOException::class)]
#[Test, Expect(OperationFailed::class)]
public function exceptions_raised_while_storing() {
$in= new MemoryInputStream('Test');
$out= new class() extends MemoryOutputStream {
public function write($bytes) { throw new IOException('Disk full'); }
public function write($bytes) { throw new OperationFailed('Disk full'); }
};

$it= $this->newFixture(self::NAME, Streams::readableUri($in))->transmit($out);
Expand Down
Loading