Skip to content

Commit

Permalink
fix: don't throw error if ProcessStartFailedException
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Jul 27, 2024
1 parent 7333dbb commit b777f6a
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 27 deletions.
8 changes: 5 additions & 3 deletions src/Parsers/Apcaccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
namespace Ginfo\Parsers;

use Ginfo\Common;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

class Apcaccess implements ParserInterface
{
public static function work(): ?array
{
$process = new Process(['apcaccess', 'status'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Parsers/Free.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ginfo\Parsers;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

class Free implements ParserInterface
Expand All @@ -17,9 +19,9 @@ private function __clone()
public static function work(): ?array
{
$process = new Process(['free', '-bw'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Parsers/Lpstat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ginfo\Parsers;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

/**
Expand All @@ -12,8 +14,9 @@ class Lpstat implements ParserInterface
public static function work(): ?array
{
$process = new Process(['lpstat', '-p'], null, ['LANG' => 'C']);
$process->run();
if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Parsers/Sensors/Ipmi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Ginfo\Parsers\Sensors;

use Ginfo\Parsers\ParserInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

/**
Expand All @@ -15,9 +17,9 @@ class Ipmi implements ParserInterface
public static function work(): ?array
{
$process = new Process(['ipmitool', 'sdr'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Parsers/Sensors/Nvidia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Ginfo\Parsers\Sensors;

use Ginfo\Parsers\ParserInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

/**
Expand All @@ -15,8 +17,9 @@ class Nvidia implements ParserInterface
public static function work(): ?array
{
$process = new Process(['nvidia-smi', '-L'], null, ['LANG' => 'C']);
$process->run();
if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Parsers/Sensors/Sensors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Ginfo\Parsers\Sensors;

use Ginfo\Parsers\ParserInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

class Sensors implements ParserInterface
Expand All @@ -18,8 +20,9 @@ private function __clone()
public static function work(): ?array
{
$process = new Process(['sensors'], null, ['LANG=C']);
$process->run();
if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Parsers/Sestatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Ginfo\Parsers;

use Ginfo\Common;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

class Sestatus implements ParserInterface
Expand All @@ -18,9 +20,9 @@ private function __clone()
public static function work(): ?array
{
$process = new Process(['sestatus'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Parsers/Smbstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ginfo\Parsers;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

/**
Expand All @@ -12,9 +14,9 @@ class Smbstatus implements ParserInterface
public static function work(): ?array
{
$process = new Process(['smbstatus'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Parsers/Systemd.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ginfo\Parsers;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

class Systemd implements ParserInterface
Expand All @@ -17,9 +19,9 @@ private function __clone()
public static function work(): ?array
{
$process = new Process(['systemctl', 'list-units', '--type', 'service', '--all'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Parsers/Who.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ginfo\Parsers;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

class Who implements ParserInterface
Expand All @@ -17,9 +19,9 @@ private function __clone()
public static function work(): ?array
{
$process = new Process(['who', '--count'], null, ['LANG' => 'C']);
$process->run();

if (!$process->isSuccessful()) {
try {
$process->mustRun();
} catch (ProcessFailedException|ProcessStartFailedException $e) {
return null;
}

Expand Down

0 comments on commit b777f6a

Please sign in to comment.