Skip to content

Commit f7f6674

Browse files
committed
Merge pull request #615 from pantheon-systems/collection_err
Accessing invalid collection members now results in error & nonzero exit
2 parents 1d6b4bb + 231f115 commit f7f6674

File tree

5 files changed

+214
-2
lines changed

5 files changed

+214
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this project starting with the 0.6.0 release will be docu
1414
- `site create-env` no longer fails to clone from an environment. (#602)
1515
- `site backups list` filtering by element fixed. (#602)
1616
- Four SSH-based commands now return with unavailable errors: `wp import`, `wp db`, `drush sql-connect`, and `drush sql-sync`. (#607)
17+
- When trying to access an invalid collection member, Terminus now exits instead of having a fatal error. (#615)
1718

1819
### Changed
1920
- Logged errors now exit with -1. (#576)

php/Terminus/Models/Collections/TerminusCollection.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Terminus\Models\Collections;
44

55
use TerminusCommand;
6+
use Terminus\Exceptions\TerminusException;
67
use Terminus\Models\TerminusModel;
78

89
abstract class TerminusCollection extends TerminusModel {
@@ -61,7 +62,15 @@ public function get($id) {
6162
if (isset($models[$id])) {
6263
return $models[$id];
6364
}
64-
return null;
65+
$model = explode('\\', $this->getMemberName());
66+
throw new TerminusException(
67+
'Could not find {model} "{id}"',
68+
array(
69+
'model' => strtolower(array_pop($model)),
70+
'id' => $id,
71+
),
72+
1
73+
);
6574
}
6675

6776
/**

tests/features/site_organizations.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ Feature: Site organizations
5757
When I run "terminus site organizations remove --site=[[test_site_name]] --org=[[enterprise_org_name]]"
5858
Then I should get:
5959
"""
60-
[[enterprise_org_uuid]] is not a member of [[test_site_name]]
60+
Could not find siteorganizationmembership "[[enterprise_org_uuid]]"
6161
"""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Finding member items in a collection
2+
3+
Scenario: Failure to find a member item in a collection
4+
@vcr collection_get_failure
5+
Given I am authenticated
6+
And a site named "[[test_site_name]]"
7+
When I run "terminus site set-connection-mode --site=[[test_site_name]] --env=invalid --mode=sftp"
8+
Then I should get:
9+
"""
10+
Could not find environment "invalid"
11+
"""

0 commit comments

Comments
 (0)