Skip to content

Commit

Permalink
Use more specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mundschenk-at committed Jun 13, 2024
1 parent 247573b commit 716dd10
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bin/class-pattern-converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
namespace PHP_Typography\Bin;

use PHP_Typography\U;
use PHP_Typography\Exceptions\Invalid_File_Exception;
use PHP_Typography\Exceptions\Invalid_Path_Exception;

/**
* Convert LaTeX hyphenation pattern files to JSON.
Expand Down Expand Up @@ -381,11 +383,12 @@ public function convert() {
* @param string[] $exceptions Extracted hyphenation exception lines. Passed by reference.
* @param string[] $comments Extracted comments lines. Passed by reference.
*
* @throws \RuntimeException Thrown when file does not exist or is not readable.
* @throws Invalid_Path_Exception Thrown when file does not exist.
* @throws Invalid_File_Exception Thrown when file exists, but is not readable.
*/
protected function convert_single_file( $url, &$patterns, &$exceptions, &$comments ): void {
if ( ! \file_exists( $url ) && 404 === File_Operations::get_http_response_code( $url ) ) {
throw new \RuntimeException( "Error: unknown pattern file '{$url}'\n" );
throw new Invalid_Path_Exception( "Error: unknown pattern file '{$url}'\n" );
}

// Status indicators.
Expand All @@ -401,7 +404,7 @@ protected function convert_single_file( $url, &$patterns, &$exceptions, &$commen
// Read the next line.
$line = $file->fgets();
if ( ! \is_string( $line ) ) {
throw new \RuntimeException( "Error reading file '{$url}'\n" );
throw new Invalid_File_Exception( "Error reading file '{$url}'\n" );
}

// Calculate current line number (instead of calling `SplFileObject::current`).
Expand Down

0 comments on commit 716dd10

Please sign in to comment.