From 8ad4997f3c1e6d01e2bd104f2ab9fd5e31c6b0f9 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 30 Jan 2020 14:46:44 -0800 Subject: [PATCH] Fix error message during symlink deletion (#11331) --- .../namespaces/FileSystemProvider.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 71f9f9a469..7b701acd14 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -3049,13 +3049,18 @@ namespace Microsoft.PowerShell.Commands { try { + // TODO: + // Different symlinks seem to vary by behavior. + // In particular, OneDrive symlinks won't remove without recurse, + // but the .NET API here does not allow us to distinguish them. + // We may need to revisit using p/Invokes here to get the right behavior directory.Delete(); } catch (Exception e) { - string error = StringUtil.Format(FileSystemProviderStrings.CannotRemoveItem, directory.FullName); - Exception exception = new IOException(error, e); - WriteError(new ErrorRecord(exception, "DeleteSymbolicLinkFailed", ErrorCategory.WriteError, directory)); + string error = StringUtil.Format(FileSystemProviderStrings.CannotRemoveItem, directory.FullName, e.Message); + var exception = new IOException(error, e); + WriteError(new ErrorRecord(exception, errorId: "DeleteSymbolicLinkFailed", ErrorCategory.WriteError, directory)); } return;