fix: address second round of Copilot review feedback

- Replace null-forgiving operator on Marshal.PtrToStringUni with
  null-coalescing fallback (AddPveClusterMemberCmdlet.cs:64)
- GetNextId now throws InvalidOperationException instead of silently
  returning 0 when API response cannot be parsed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-24 18:47:43 -05:00
parent e54f9fb749
commit 51b51354ef
2 changed files with 5 additions and 4 deletions
@@ -396,10 +396,11 @@ namespace PSProxmoxVE.Core.Services
{ {
var response = client.GetAsync(resource).GetAwaiter().GetResult(); var response = client.GetAsync(resource).GetAwaiter().GetResult();
var data = JObject.Parse(response)["data"]; var data = JObject.Parse(response)["data"];
// The API returns the ID as a string, parse it to int if (data == null)
if (data != null && int.TryParse(data.ToString(), out var id)) throw new InvalidOperationException("API response for next VMID did not contain a 'data' field.");
if (int.TryParse(data.ToString(), out var id))
return id; return id;
return 0; throw new InvalidOperationException($"API returned unexpected next VMID value: '{data}'");
} }
finally finally
{ {
@@ -61,7 +61,7 @@ namespace PSProxmoxVE.Cmdlets.Cluster
try try
{ {
ptr = Marshal.SecureStringToGlobalAllocUnicode(Password); ptr = Marshal.SecureStringToGlobalAllocUnicode(Password);
var plainPassword = Marshal.PtrToStringUni(ptr)!; var plainPassword = Marshal.PtrToStringUni(ptr) ?? string.Empty;
var linkDict = ParseLinks(Links); var linkDict = ParseLinks(Links);