cli-microsoft365: Bug report: Running CLI on Azure Function throws errors because of Spinner output
Description
When running the CLI 6.3 and above on an Azure Function, the following vague exceptions are thrown. This is probably caused by the Spinner trying to pipe output to the console, while the Azure Function may not be allowing this type of writing output.
[2023-03-29T11:56:41.954Z] Result: ERROR: - Running command...
[2023-03-29T11:56:41.955Z]
[2023-03-29T11:56:41.956Z] Exception :
[2023-03-29T11:56:41.957Z] Type : System.Management.Automation.RemoteException
[2023-03-29T11:56:41.958Z] ErrorRecord :
[2023-03-29T11:56:41.959Z] Exception :
[2023-03-29T11:56:41.960Z] Type : System.Management.Automation.ParentContainsErrorRecordException
[2023-03-29T11:56:41.960Z] Message : - Running command...
[2023-03-29T11:56:41.961Z] HResult : -2146233087
[2023-03-29T11:56:41.962Z] CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
[2023-03-29T11:56:41.963Z] FullyQualifiedErrorId : RuntimeException
[2023-03-29T11:56:41.965Z] Message : - Running command...
[2023-03-29T11:56:41.966Z] HResult : -2146233087
[2023-03-29T11:56:41.967Z] TargetObject : - Running command...
[2023-03-29T11:56:41.968Z] CategoryInfo : NotSpecified: (- Running command...:String) [], RemoteException
[2023-03-29T11:56:41.969Z] FullyQualifiedErrorId : NativeCommandError
[2023-03-29T11:56:41.970Z] InvocationInfo :
[2023-03-29T11:56:41.971Z] MyCommand : node.exe
[2023-03-29T11:56:41.972Z] ScriptLineNumber : 24
[2023-03-29T11:56:41.974Z] OffsetInLine : 5
[2023-03-29T11:56:41.975Z] HistoryId : -1
[2023-03-29T11:56:41.976Z] ScriptName : C:\Users\MartinLingstuyl\AppData\Roaming\npm\m365.ps1
[2023-03-29T11:56:41.977Z] Line : & "node$exe" "$basedir/node_modules/@pnp/cli-microsoft365/dist/index.js" $args
[2023-03-29T11:56:41.978Z]
[2023-03-29T11:56:41.978Z] PositionMessage : At C:\Users\MartinLingstuyl\AppData\Roaming\npm\m365.ps1:24 char:5
[2023-03-29T11:56:41.981Z] + & "node$exe" "$basedir/node_modules/@pnp/cli-microsoft365/dist/i .
[2023-03-29T11:56:41.983Z] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2023-03-29T11:56:41.984Z] PSScriptRoot : C:\Users\MartinLingstuyl\AppData\Roaming\npm
[2023-03-29T11:56:42.065Z] PSCommandPath : C:\Users\MartinLingstuyl\AppData\Roaming\npm\m365.ps1
[2023-03-29T11:56:42.067Z] InvocationName : &
[2023-03-29T11:56:42.069Z] CommandOrigin : Internal
[2023-03-29T11:56:42.084Z] ScriptStackTrace : at <ScriptBlock>, C:\Users\MartinLingstuyl\AppData\Roaming\npm\m365.ps1: line 24
Steps to reproduce
Create a new VS Code project with PowerShell, use a CLI command and press F5
CLI for Microsoft 365 version
6.4 (beta)
nodejs version
16.15.0
Operating system (environment)
Windows, Azure Function
Shell
PowerShell
Additional Info
If we would be able to hide the spinner with a config key, this may be avoided. Also, we should add this config key to the settings that will be added when running the new m365 setup command that is being created in #4216.
Implementation
We agreed on adding a config key showSpinner with the default value true. If it’s false the spinner should not be rendered.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Add config key to disable spinner. Closes #4692 — committed to martinlingstuyl/cli-microsoft365 by martinlingstuyl a year ago
That’s right yes, I’ll assign myself
Makes sense. Let’s make that a config setting
Yes and no. Like you said: it’s Functions’ PowerShell runtime that decides to treat stderr, which is a legitimate output stream for non-error messages, like exception. Ideally, that’s something that should be configurable on Functions runtime. In this case we’d work around Functions runtime settings, rather than CLI using stderr to output messages. You’d have the same issue when you’d choose to run CLI in verbose or debug mode.
Correct. This is why we already offer the ability to redirect all output to stdout. This wouldn’t be feasible for spinners though, because it would cause CLI output would become useless. So the only way really is to suppress spinners altogether.
Interesting! Though that does not occur in my local PowerShell 7.x sessions. It’s only doing this within the context of Azure Function as far as I’ve currently seen.
As yo the solutions:
Feels more like a workaround. If you have a large script, it’s not really feasible to have this on every line.
+1 on this.
Let me try if
m365 cli config set --key errorOutput --value stdoutworks as well.