From 5db6029f2c1238687947c55bd63ede268bd38bd9 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Thu, 10 Sep 2020 21:58:16 +0200 Subject: [PATCH] Give feedback when a relation can't be resolved (#1052) Improves https://github.com/barryvdh/laravel-ide-helper/pull/1017 slightly --- src/Console/ModelsCommand.php | 7 +++++-- tests/Console/ModelsCommand/DynamicRelations/Test.php | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 55a845d..40c32ed 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -38,6 +38,7 @@ use ReflectionObject; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Throwable; /** * A command to generate autocomplete information for your IDE @@ -277,7 +278,7 @@ class ModelsCommand extends Command $output .= $this->createPhpDocs($name); $ignore[] = $name; $this->nullableColumns = []; - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->error('Exception: ' . $e->getMessage() . "\nCould not analyze class $name.\n\nTrace:\n" . $e->getTraceAsString()); @@ -601,7 +602,9 @@ class ModelsCommand extends Command $relationObj = Relation::noConstraints(function () use ($model, $method) { try { return $model->$method(); - } catch (\Throwable $e) { + } catch (Throwable $e) { + $this->warn(sprintf('Error resolving relation model of %s:%s() : %s', get_class($model), $method, $e->getMessage())); + return null; } }); diff --git a/tests/Console/ModelsCommand/DynamicRelations/Test.php b/tests/Console/ModelsCommand/DynamicRelations/Test.php index 36e0b45..bc248b5 100644 --- a/tests/Console/ModelsCommand/DynamicRelations/Test.php +++ b/tests/Console/ModelsCommand/DynamicRelations/Test.php @@ -17,8 +17,15 @@ class Test extends AbstractModelsCommand '--write' => true, ]); + $errors = <<assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertStringContainsString($errors, $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } }