PowerShell / SecretManagement

PowerShell module to consistent usage of secrets through different extension vaults
MIT License
317 stars 46 forks source link

NoClobber should not throw an exception #128

Closed jdhitsolutions closed 3 years ago

jdhitsolutions commented 3 years ago

This might be related to #95 but certainly isn't nice. If I run -NoClobber and try to set an existing secret, I get an exception.

image

Yes, I could use an ErrorAction to suppress it, but I shouldn't have to. At best, I could see a warning message indicating the secret wasn't set. Or don't show anything and provide that detail in verbose output.

Or is there a bug? I re-ran the command with Verbose output.

image

That first verbose message implies -NoClobber wasn't detected.

jdhitsolutions commented 3 years ago

Did a little more digging and I think this is bug. My testing was in Windows PowerShell. Running the same command in PowerShell 7 provides the experience I was expecting.

image

I looked at the source and it looks like you are using a chain operator which Windows PowerShell can't use.

PaulHigin commented 3 years ago

No, this is by design. Set-Secret will overwrite an existing secret by default. Using the -NoClobber switch means it will fail to store the secret. Since the cmdlet operation failed, a command terminating error is thrown.

jdhitsolutions commented 3 years ago

I guess that really is the behavior. I tested other commands with a -NoClobber parameter and they do in fact throw an exception. Guess I had a misconception on this parameter.