microsoftgraph / microsoftgraph/msgraph-sdk-powershell

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

Aperta
#274 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

AutoREST-dependency Blocked Request: Kiota
Lingua principale
C#
Stelle
898
Fork
230
Merge medio
2g 5h
PR unite (30g)
31

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo la ricerca Get-MgUser mostrata nell’issue e analizza la gestione degli errori e la costruzione di ErrorRecord del cmdlet generato. Il lavoro è completato quando una risorsa mancante segnala ObjectNotFound e il valore Activity non presenta più il suffisso inspiegato _Get, con il comportamento verificato tramite l’output CategoryInfo visualizzato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, powershell
Ambito
cli
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.