microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Set the property error category when an item is not found, and clean up Activity property

Offen
#274 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

AutoREST-dependency Blocked Request: Kiota
Vorherrschende Sprache
C#
Sterne
898
Forks
230
Ø Merge
2 T. 5 Std.
Gemergte PRs (30 T.)
31

Beschreibung

If I attempt to retrieve a resource that does not exist, I get an exception. That exception currently shows the category for the error as InvalidOperation, which is incorrect. The operation was valid, but the resource was not found.

For example, run this:

Get-MgUser -UserId (New-Guid).Guid -ErrorVariable lookupError
$lookupError.CategoryInfo

This script results in an error from the first command (you'll get an error because there is no user with that random GUID that you just created), and then it shows the category information for the error. The output from the second command will look something like this:

Category   : InvalidOperation
Activity   : Get-MgUser_Get
Reason     : Exception
TargetName : { UserId = 4854a621-9117-4cd3-999b-5f7ca6882432, Property = , ExpandProperty =  }
TargetType : <>f__AnonymousType0`3

The categorization of this error is being done incorrectly, and that makes it difficult for scripters to properly handle a scenario when a resource is not found. For example, you delete a resource and then want to make sure that it was deleted. The category of InvalidOperation should be reserved for operations that failed due to the operation being invalid. When a resource is not found, you should use [System.Management.Automation.ErrorCategory]::ObjectNotFound as the category instead.

Further, for the Activity property, why does it show an extra "_Get" at the end? I invoked Get-MgUser. I expect the activity would be simply Get-MgUser. What is the significance of the extra verb appended on the end of that string?
AB#7414

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die im Issue gezeigte Get-MgUser-Suche zu reproduzieren, und untersuche die Fehlerbehandlung und die Erstellung des ErrorRecord des generierten Cmdlets. Die Arbeit ist abgeschlossen, wenn eine fehlende Ressource ObjectNotFound meldet und der Activity-Wert nicht mehr das unerklärte Suffix _Get enthält, wobei das Verhalten anhand der angezeigten CategoryInfo-Ausgabe verifiziert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, powershell
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.