Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise error messages to include Linux debugging help #220

Merged
merged 3 commits into from
Apr 3, 2021
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
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
mattstauffer marked this conversation as resolved.
Show resolved Hide resolved
{
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();
}
}