Skip to content

Commit

Permalink
Merge pull request #220 from benholmen/bmh/improve-linux-messaging
Browse files Browse the repository at this point in the history
Revise error messages to include Linux debugging help
  • Loading branch information
mattstauffer authored Apr 3, 2021
2 parents c563a18 + b47db5b commit 90ab981
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/Exceptions/DockerMissingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function render($request = null): void
$console->line('');
$console->line($shell->formatErrorMessage('Docker is not installed.'));
$console->line('');
$console->line($shell->formatErrorMessage('Please visit https://docs.docker.com/docker-for-mac/install/'));
$console->line($shell->formatErrorMessage('Please visit https://docs.docker.com/get-docker/'));
$console->line($shell->formatErrorMessage('for information on how to install Docker for your machine.'));
}
}
58 changes: 58 additions & 0 deletions app/Exceptions/DockerNotAvailableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Exceptions;

use App\Shell\Environment;
use App\Shell\Shell;
use Exception;

class DockerNotAvailableException extends Exception
{
public function render($request = null): void
{
$console = app('console');
$shell = app(Shell::class);

$console->line('');
$console->line($shell->formatErrorMessage('Docker is not available.'));
$console->line('');

if (in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'Windows'])) {
$osSpecificHelp = 'helpFor' . ucfirst(PHP_OS_FAMILY);
$this->$osSpecificHelp($console);
}
}

protected function helpForDarwin($console)
{
$console->line('Open Docker for Mac or run:');
$console->line(' open --background -a Docker');
$console->line('to start the Docker service.');
}

protected function helpForLinux($console)
{
$environment = app(Environment::class);
$shell = app(Shell::class);

$console->line('Verify that the Docker service is running:');
$console->line(' sudo systemctl status docker');
$console->line('Start the Docker service:');
$console->line(' sudo systemctl start docker');

if (! $environment->userIsInDockerGroup()) {
$console->line('');
$console->line($shell->formatErrorMessage('You are not in the docker group.'));
$console->line('');
$console->line('This is required to run Docker as a non-root user.');
$console->line('Add your user to the docker group by running:');
$console->line(' sudo usermod -aG docker ${USER}');
$console->line('and restart your session.');
}
}

protected function helpForWindows($console)
{
$console->line('Open Docker for Windows to start the Docker service.');
}
}
22 changes: 0 additions & 22 deletions app/Exceptions/DockerNotRunningException.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/InitializesCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App;

use App\Exceptions\DockerMissingException;
use App\Exceptions\DockerNotRunningException;
use App\Exceptions\DockerNotAvailableException;
use App\Shell\Docker;

trait InitializesCommands
Expand All @@ -19,7 +19,7 @@ public function initializeCommand(): void
}

if (! app(Docker::class)->isDockerServiceRunning()) {
throw new DockerNotRunningException;
throw new DockerNotAvailableException;
}
}
}
5 changes: 5 additions & 0 deletions app/Shell/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public function netstatCmd(): string

return $netstatCmd;
}

public function userIsInDockerGroup(): bool
{
return $this->shell->execQuietly('groups | grep docker')->isSuccessful();
}
}

0 comments on commit 90ab981

Please sign in to comment.