{"record":{"id":"21e2c5e11f61939c","repo":"BornToBeRoot/NETworkManager","slug":"message-joined-powershell-error-streams","errorCode":null,"errorMessage":"message (joined PowerShell error streams)","messagePattern":"message \\(joined PowerShell error streams\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Source/NETworkManager.Models/Network/NeighborTable.cs","lineNumber":407,"sourceCode":"        {\n            RunspaceLock.Release();\n        }\n    }\n\n    /// <summary>\n    /// Throws an <see cref=\"Exception\"/> whose message is the joined PowerShell error\n    /// stream when <paramref name=\"ps\"/> reported one or more errors.\n    /// </summary>\n    private static void ThrowOnError(SMA.PowerShell ps)\n    {\n        if (ps.Streams.Error.Count == 0)\n            return;\n\n        var message = string.Join(Environment.NewLine, ps.Streams.Error);\n\n        Log.Warn($\"PowerShell error: {message}\");\n\n        throw new Exception(message);\n    }\n\n    #endregion\n}\n","sourceCodeStart":389,"sourceCodeEnd":412,"githubUrl":"https://github.com/BornToBeRoot/NETworkManager/blob/2780d65469917a296dbc15f206107d72e2d0115c/Source/NETworkManager.Models/Network/NeighborTable.cs#L389-L412","documentation":"ThrowOnError inspects ps.Streams.Error after running NetNeighbor PowerShell commands (New-/Remove-NetNeighbor, or clearing the table). If any error records exist, they are joined with Environment.NewLine, logged as a warning, and thrown as a generic Exception carrying the full PowerShell error text.","triggerScenarios":"AddEntryAsync with an invalid IP/MAC or an entry already present; DeleteEntryAsync for a neighbor that does not exist; DeleteTableAsync when entries cannot be removed (in-use or permission issues); running without elevation so NetNeighbor cmdlets are denied.","commonSituations":"Non-admin execution (NetNeighbor requires elevation); duplicate static ARP entries; malformed MAC address strings; interface index/IPAddress not matching an existing interface.","solutions":["Run the application elevated; NetNeighbor cmdlets require administrator rights.","Validate the IP address and physical (MAC) address format before calling AddEntryAsync.","For deletes, check the entry exists first or tolerate 'not found' errors by parsing the message.","Catch the exception and show the multi-line PowerShell error to the user; it names the failing cmdlet and parameter."],"exampleFix":"// before\nawait NeighborTable.AddEntryAsync(new NeighborTableEntryInfo { IPAddress = ip, PhysicalAddress = mac, ... }); // throws on bad input\n// after\nif (!System.Net.IPAddress.TryParse(ip, out _) || !System.Net.NetworkInformation.PhysicalAddress.Parse(mac.Replace('-', ':'))...)\n    throw new ArgumentException(\"Invalid IP or MAC address\");\nawait NeighborTable.AddEntryAsync(entry);","handlingStrategy":"validation","validationCode":"null","typeGuard":"static bool IsValidNeighborEntry(NeighborTableEntryInfo e) => e != null && e.IPAddress != null && e.PhysicalAddress != null && !e.PhysicalAddress.Equals(System.Net.NetworkInformation.PhysicalAddress.None) && e.InterfaceIndex > 0;","tryCatchPattern":"try\n{\n    await NeighborTable.AddEntryAsync(entry);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"already exists\") || ex.Message.Contains(\"Failed\"))\n{\n    Log.Warn($\"NetNeighbor error: {ex.Message}\");\n    // show the multi-line PowerShell error to the user\n}","preventionTips":["Run elevated; NetNeighbor cmdlets require administrator rights.","Validate IP/MAC/interface index before calling Add/Delete.","Treat duplicate-entry errors as recoverable; parse the message rather than assuming a hard failure."],"tags":["powershell","arp","elevation","network"],"backgroundTag":"api-error-response","analyzedSha":"2780d65469917a296dbc15f206107d72e2d0115c","analyzedAt":"2026-09-12T17:00:17.986Z","contentChangedAt":"2026-09-12T17:00:17.986Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}