github / github/gh-gei

`reclaim-mannequin --csv` exits after `Target must be a member of the XXX organization` error, rather than continuing to next row

Open
#1,103 9 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
C#
Stars
478
Forks
146
Avg merge
7d 21h
Merged PRs (30d)
2

Description

## Description

When running `reclaim-mannequin --csv`, the intent is that one reclaim failing doesn't cause the command to exit.

Instead, a warning should be logged, and the command should continue with reclaiming other mannequins in the CSV.

This isn't currently working as expected, and at least the `Target must be a member of the XXX organization` error causing the entire command to exist.

Looking at the code, this seems to be because `ReclaimMannequinSkipInvitation` throws an exception rather than returning a `ReattributeMannequinToUserResult`, and our error handling code which keeps the reclaims going seems to assume that there'll be a `ReattributeMannequinToUserResult` with `Errors` attached.

## Reproduction Steps

1. Run a migration, leaving unclaimed more than one unclaimed mannequin
2. Use `generate-mannequin-csv` to generate a mannequin CSV
3. Fill out the first mannequin with a user who is not a member of the target organization
4. Run `reclaim-mannequin --csv`
5. The command errors after processing the first row - very slowly because of lots of unnecessary retries... - and the second row is not considered.

```
[2023-08-21 15:48:16] [ERROR] OctoshiftCLI.OctoshiftCliException: Target must be a member of the XXX organization
at OctoshiftCLI.Services.GithubClient.EnsureSuccessGraphQLResponse(JObject response)
at OctoshiftCLI.Services.GithubClient.PostGraphQLAsync(String url, Object body, Dictionary`2 customHeaders)
at OctoshiftCLI.Services.GithubApi.<>c__DisplayClass43_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Func`5 onRetryAsync, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider, Boolean continueOnCapturedContext)
at Polly.AsyncPolicy.ExecuteAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
at OctoshiftCLI.RetryPolicy.Retry[T](Func`1 func)
at OctoshiftCLI.Services.GithubApi.ReclaimMannequinSkipInvitation(String orgId, String mannequinId, String targetUserId)
at OctoshiftCLI.Services.ReclaimService.ReclaimMannequins(String[] lines, String githubTargetOrg, Boolean force, Boolean skipInvitation)
at OctoshiftCLI.Commands.ReclaimMannequin.ReclaimMannequinCommandHandler.Handle(ReclaimMannequinCommandArgs args)
at OctoshiftCLI.Extensions.CommandExtensions.RunHandler[TArgs,THandler](TArgs args, ServiceProvider sp, CommandBase`2 command)
at OctoshiftCLI.Extensions.CommandExtensions.<>c__DisplayClass1_0`3.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext )
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<b__0>d.MoveNext()

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.