## I intend to create a symbolic link `foo` pointing to the directory 'bar'.
## However, I incorrectly specified the target directory path as the argument to `-Path`.
mkdir F:\temp\bar
New-Item -ItemType SymbolicLink -Path F:\temp\bar -Value F:\temp\foo
Error message should be meaningful and useful
PS:62> New-Item -ItemType SymbolicLink -Path F:\temp\bar -Value F:\temp\foo
New-Item : NewItemIOError
At line:1 char:1
+ New-Item -ItemType SymbolicLink -Path F:\temp\bar -Value F:\temp\foo
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceExists: (F:\temp\bar:String) [New-Item], IOException
+ FullyQualifiedErrorId : NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-alpha
PSEdition Core
BuildVersion 3.0.0.0
CLRVersion
GitCommitId v6.0.0-alpha.18-54-g3e416fb6422c0c25f63bd0228edd2403ae2c78d4
OS Linux 4.8.0-41-generic #44~16.04.1-Ubuntu SMP Fri Mar 3 17:11:16 ...
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
@jeffbi you have a lot experiences related to symbolic link, can you please have a quick look at this issue and see if it's easy to fix?
@daxian-dbw Well, the error message is correct, as far as it goes---the name given as the symlink path does already exist.
What would be preferred? We could try to be a little more clever and if we're trying to create a symlink and a) the item on -Path already exists and b) the item on -Value does not, we could do something "git-ish" like:
Item F:\tmp\bar already exists. Did you mean "-Path F:\tmp\foo -Value F:\tmp\bar?"
Not really a prompt, just a hint. Of course we'd probably want to know if target path was given via -Value or -Target and adjust the message accordingly.
Or just a new message specific to symlinks when the path item exists? Either one would be fairly easy.
Simple Item F:\tmp\bar already exists looks good in all cases.
It looks like this is the one place in the FileSystemProvider.cs code file that an ErrorRecord is being built from a newly-constructed IOException object without going out to FileSystemProviderStrings. It just plugs that ugly, non-localized text into the error:
C#
WriteError(new ErrorRecord(new IOException("NewItemIOError"), "NewItemIOError", ErrorCategory.ResourceExists, path));
I think we just need a new message and to change the code to use it.
I'd really like to change the error ID from "NewItemIOError" to "SymLinkExists" if for no other reason it will make for better tests. Or would that be a breaking change?
It is a breaking change but acceptable and reasonable.
@jeffbi Thanks for the quick fix!
Most helpful comment
It is a breaking change but acceptable and reasonable.