Skip to content

Commit

Permalink
Improve error reporting for failed dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Mar 10, 2022
1 parent b0a5e03 commit 17152c3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/DbDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public function checkIfDumpWasSuccessFul(Process $process, string $outputFile):
}

if (! file_exists($outputFile)) {
throw DumpFailed::dumpfileWasNotCreated();
throw DumpFailed::dumpfileWasNotCreated($process);
}

if (filesize($outputFile) === 0) {
throw DumpFailed::dumpfileWasEmpty();
throw DumpFailed::dumpfileWasEmpty($process);
}
}

Expand Down
38 changes: 33 additions & 5 deletions src/Exceptions/DumpFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,44 @@ class DumpFailed extends Exception
{
public static function processDidNotEndSuccessfully(Process $process): static
{
return new static("The dump process failed with exitcode {$process->getExitCode()} : {$process->getExitCodeText()} : {$process->getErrorOutput()}");
$processOutput = static::formatProcessOutput($process);

return new static("The dump process failed with a none successful exitcode.{$processOutput}");
}

public static function dumpfileWasNotCreated(Process $process): static
{
$processOutput = static::formatProcessOutput($process);

return new static("The dumpfile could not be created.{$processOutput}");
}

public static function dumpfileWasNotCreated(): static
public static function dumpfileWasEmpty(Process $process): static
{
return new static('The dumpfile could not be created');
$processOutput = static::formatProcessOutput($process);

return new static("The created dumpfile is empty.{$processOutput}");
}

public static function dumpfileWasEmpty(): static
protected static function formatProcessOutput(Process $process): string
{
return new static('The created dumpfile is empty');
$output = $process->getOutput() ?: '<no output>';
$errorOutput = $process->getErrorOutput() ?: '<no output>';
$exitCodeText = $process->getExitCodeText() ?: '<no exit text>';

return <<<CONSOLE
Exitcode
========
{$process->getExitCode()}: {$exitCodeText}
Output
======
{$output}
Error Output
============
{$errorOutput}
CONSOLE;
}
}

0 comments on commit 17152c3

Please sign in to comment.