Skip to content

Commit

Permalink
Throw exception instead of silently logging issues occurred during scan
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Apr 11, 2024
1 parent 7d6c88e commit e93ecbe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
4 changes: 0 additions & 4 deletions src/Psalm/Internal/Codebase/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,6 @@ static function (): void {
$this->argument_map[$file_path] = $argument_map;
}
}

if ($pool->didHaveError()) {
exit(1);
}
} else {
$i = 0;

Expand Down
4 changes: 0 additions & 4 deletions src/Psalm/Internal/Codebase/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ function () {
);
}
}

if ($pool->didHaveError()) {
exit(1);
}
} else {
$i = 0;

Expand Down
22 changes: 5 additions & 17 deletions src/Psalm/Internal/Fork/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ final class Pool
/** @var resource[] */
private array $read_streams = [];

private bool $did_have_error = false;

/** @var ?Closure(mixed): void */
private ?Closure $task_done_closure = null;

Expand Down Expand Up @@ -361,6 +359,7 @@ private function readResultsFromChildren(): array
if ($message instanceof ForkProcessDoneMessage) {
$terminationMessages[] = $message->data;
} elseif ($message instanceof ForkTaskDoneMessage) {
$done[(int)$file] = true;

Check failure on line 362 in src/Psalm/Internal/Fork/Pool.php

View workflow job for this annotation

GitHub Actions / build

PossiblyUndefinedVariable

src/Psalm/Internal/Fork/Pool.php:362:29: PossiblyUndefinedVariable: Possibly undefined variable $done, first seen on line 362 (see https://psalm.dev/018)

Check failure on line 362 in src/Psalm/Internal/Fork/Pool.php

View workflow job for this annotation

GitHub Actions / build

MixedArrayAssignment

src/Psalm/Internal/Fork/Pool.php:362:29: MixedArrayAssignment: Cannot access array value on mixed variable $done[int] (see https://psalm.dev/117)
if ($this->task_done_closure !== null) {
($this->task_done_closure)($message->data);
}
Expand All @@ -378,17 +377,15 @@ private function readResultsFromChildren(): array
}
throw new Exception($message->message);
} else {
error_log('Child should return ForkMessage - response type=' . gettype($message));
$this->did_have_error = true;
throw new Exception('Child should return ForkMessage - response type=' . gettype($message));
}
}
}

// If the stream has closed, stop trying to select on it.
if (feof($file)) {
if ($content[(int)$file] !== '') {
error_log('Child did not send full message before closing the connection');
$this->did_have_error = true;
if ($content[(int)$file] !== '' || !isset($done[(int)$file])) {
throw new Exception('Child did not send full message before closing the connection');
}

fclose($file);
Expand Down Expand Up @@ -450,21 +447,12 @@ public function wait(): array
* @psalm-suppress UndefinedConstant
*/
if ($term_sig !== SIGALRM) {
$this->did_have_error = true;
error_log("Child terminated with return code $return_code and signal $term_sig");
throw new Exception("Child terminated with return code $return_code and signal $term_sig");
}
}
}
}

return $content;
}

/**
* Returns true if this had an error, e.g. due to memory limits or due to a child process crashing.
*/
public function didHaveError(): bool
{
return $this->did_have_error;
}
}

0 comments on commit e93ecbe

Please sign in to comment.