Skip to content

Commit 47eb2b8

Browse files
authored
fix(cli): tell the two trace init project dead ends apart (PFM-7409) (#3466)
1 parent 59d1818 commit 47eb2b8

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎app/cli/cmd/trace_init_identity.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,15 @@ func resolveInteractiveProject(ctx context.Context, lister projectLister, p prom
357357
// Creating one is a permission of the organization role, not of any project:
358358
// an organization contributor administering every project it can see still
359359
// cannot create another. With nothing to pick either, there is no way
360-
// forward, so say so instead of asking.
360+
// forward, so say so instead of asking. Seeing no project at all and seeing
361+
// only projects that cannot be written to are different dead ends, and what
362+
// there is to ask an administrator for differs with them.
361363
if !listing.CanCreateProject && len(writable) == 0 {
362-
return nil, errors.New("you cannot create projects in this organization, and none of the projects you can see accepts a new workflow; ask an administrator for access to one")
364+
if len(readOnly) == 0 {
365+
return nil, errors.New("you do not belong to any project in this organization, and cannot create a new one; ask an administrator to add you to one")
366+
}
367+
368+
return nil, errors.New("you can only view the projects in this organization, and cannot create a new one; ask an administrator for write access to one")
363369
}
364370

365371
// Nothing to choose from, so go straight to naming one rather than showing a

‎app/cli/cmd/trace_init_identity_test.go‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,23 @@ func TestResolveInteractiveProject(t *testing.T) {
685685
},
686686
{
687687
// Nothing to pick and nothing to create is a dead end, so it says so
688-
// instead of asking for a name the control plane would refuse.
689-
name: "no writable project and no permission to create says so",
688+
// instead of asking for a name the control plane would refuse. The
689+
// projects are there to be seen, so the reason is the missing write
690+
// access, not a missing membership.
691+
name: "projects that can only be viewed and no permission to create says so",
690692
readOnly: []string{"payments"},
691693
cannotCreate: true,
692694
repoDir: repoDirMyRepo,
693-
wantErr: "you cannot create projects in this organization",
695+
wantErr: "you can only view the projects in this organization, and cannot create a new one",
696+
},
697+
{
698+
// Seeing nothing at all is a different dead end: talking about the
699+
// projects the caller can see, or about workflows, describes neither
700+
// what happened nor what to ask an administrator for.
701+
name: "an organization with no project in sight says the membership is missing",
702+
cannotCreate: true,
703+
repoDir: repoDirMyRepo,
704+
wantErr: "you do not belong to any project in this organization, and cannot create a new one",
694705
},
695706
}
696707

0 commit comments

Comments
 (0)