PSSlack icon indicating copy to clipboard operation
PSSlack copied to clipboard

Cannot hide warnings

Open webbexpert opened this issue 7 years ago • 5 comments

Hi!

Attempted the following command: New-SlackMessageAttachment -Pretext "Deployment to /E:$($EnvironmentName)$($testMessage)" -Color Red -Title $NewVersion -TitleLink $BuildInfoUrl -Fields $Fields -Text "Version Info: $($VersionInfoUrl)" -Fallback $NewVersion -WarningAction SilentlyContinue -InformationAction SilentlyContinue -ErrorAction SilentlyContinue | New-SlackMessage -Username 'Bot' -Channel $Channel -IconEmoji :pushpin: -WarningAction SilentlyContinue | Send-SlackMessage -Token $Token -WarningAction SilentlyContinue | Out-Null

Note the usage of -WarningAction SilentlyContinue, however it does not appear to be honored as the script results with the following messages when calling New-SlackMessageAttachment:

WARNING: Did not find config file C:\Program Files\WindowsPowerShell\Modules\PSSlack\0.0.18\XX-XXX-PSSlack.xml, attempting to create WARNING: Failed to create config file C:\Program Files\WindowsPowerShell\Modules\PSSlack\0.0.18\XXX-XXX-PSSlack.xml: Access to the path 'C:\Program Files\WindowsPowerShell\Modules\PSSlack\0.0.18\XXX-XXX-PSSlack.xml' is denied. WARNING: Error importing PSSlack config: Could not find file 'C:\Program Files\WindowsPowerShell\Modules\PSSlack\0.0.18\XXX-XXX-PSSlack.xml'.

The easy way to fix both the error writing to the modules folder would be to move it to %temp% instead. I'm not sure what the purpose of the settings file, but might be safer to place it in a user temp instead of the module folder. Thanks in advance!

webbexpert avatar Jul 01 '17 20:07 webbexpert

Hiyo!

If you explicitly Import-Module PSSlack -WarningAction Ignore ahead of running that, you might avoid the warning. Completely agree, we'll look at moving the config file to $env:APPDATA similar to some other modules. Might be a little while, feel free to take a stab if you'd like!

Warren

RamblingCookieMonster avatar Aug 11 '17 00:08 RamblingCookieMonster

I'm curious what the configuration file is for? In the examples it shows you can pass to it everything you need. Specifically, I wanted to use this in an AWS Lambda function but it fails with configuration file errors.

jwhipp avatar Apr 10 '20 21:04 jwhipp

I'm also trying to use the module in a Lambda, is there a workaround?

christamlyn-bridge avatar Jun 11 '20 15:06 christamlyn-bridge

config file doesn't make sense in a lambda context. Does importing with warningaction ignore not suffice?

fwiw - the intention of the config file is mostly for CLI-ish use - set your config once, and don't deal with it again.

RamblingCookieMonster avatar Jun 19 '20 18:06 RamblingCookieMonster

@RamblingCookieMonster Sorry, hadn't had a chance to get back to this until today.

I tried using Import-Module PSSlack -WarningAction Ignore a head of attempting to send a slack message, still doesn't work. Appears writing the file is required:

START RequestId: 49ec9d63-4a23-4192-ba47-87e89ec2f74e Version: $LATEST
Importing module ./Modules/PSSlack/0.1.0/PSSlack.psd1
[Error] - Cannot bind argument to parameter 'Path' because it is null.
[Warning] - Did not find config file , attempting to create
[Warning] - Failed to create config file : Cannot bind argument to parameter 'Path' because it is null.
[Warning] - Error importing PSSlack config: Cannot bind argument to parameter 'Path' because it is null.

An exception was thrown when the constructor for type 'Slack_PS_Test.Bootstrap' was invoked. Check inner exception for more details.: LambdaException


   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
Cannot bind argument to parameter 'Path' because it is null.: ParameterBindingValidationException
   at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost..ctor()
   at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost..ctor(String powerShellScriptFileName)
   at Slack_PS_Test.Bootstrap..ctor() in /tmp/slack-message/Bootstrap.cs:line 9


jwhipp avatar Jul 23 '20 21:07 jwhipp