Skip to content

No Error Displayed When $ErrorView Set to ConciseView #12191

Closed

Description

In PS7 with $ErrorView set to ConciseView a custom function in a script module does not display an error, but an error is recorded in $Error. Changing to NormalView fixes this issue. I have tested the same command in VS Code's Integrated Terminal running PS7 with ConciseView and an error is output as expected. I can't explain why this works differently based on the host.

image

The error itself is coming from Invoke-RestMethod which is reaching out to an Office 365 REST API. I don't see the same behavior with built in commands.


Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Mar 24, 2020
  2. daxian-dbw commented on Mar 24, 2020

    @daxian-dbw
    Member

    Matt McNabb (@mattmcnabb) Could you please provide a repro for us to investigate?

  3. mattmcnabb commented on Mar 25, 2020

    @mattmcnabb
    Author

    Dongbo Wang (@daxian-dbw) here's the actual code I'm running:

    https://github.com/mattmcnabb/O365ServiceCommunications/blob/master/Source/Public/Connect-O365ServiceCommunications.ps1

    There's not much to it. I have this issue when I run this command with a bad value for $ClientSecret and get an error from the server.

    GitHub
    A Powershell module for monitoringOffice 365 Service Health! - mattmcnabb/O365ServiceCommunications
  4. SteveL-MSFT commented on Mar 27, 2020

    @SteveL-MSFT
    Member

    Matt McNabb (@mattmcnabb), I tried your script with PS7 and got this error:

    PS> Connect-O365ServiceCommunications -ClientID (new-guid) -ClientSecret 2 -TenantID (new-guid)                                                                                                                                                                                                                                                                                                                                             Invoke-RestMethod:
    Line |
      28 |      $Response = Invoke-RestMethod -Method Post -Uri $Url -Body $Body
         |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | {"error":"invalid_request","error_description":"AADSTS90002: Tenant '94451173-27af-4457-9369-571accb75354' not found. This may happen if there are no active subscriptions for the tenant. Check to make sure you have the correct tenant ID. Check with your subscription administrator.\r\nTrace ID: e3531849-ac96-40e0-b31b-d575c3091c00\r\nCorrelation ID: 96f214bb-c6b2-41f1-b7e1-e2cc47832376\r\nTimestamp: 2020-03-27 20:29:10Z","error_codes":[90002],"timestamp":"2020-03-27 20:29:10Z","trace_id":"e3531849-ac96-40e0-b31b-d575c3091c00","correlation_id":"96f214bb-c6b2-41f1-b7e1-e2cc47832376","error_uri":"https://login.microsoftonline.com/error?code=90002"}
    InvalidOperation:
    Line |
      29 |      $Script:SCConnection = [O365ServiceCommunications_Connection]@{
         |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Unable to find type [O365ServiceCommunications_Connection].

    Need a better repro. What size is your terminal? If you can repro, can you output $host.ui.RawUI.WindowSize?

  5. mattmcnabb commented on Mar 27, 2020

    @mattmcnabb
    Author

    Steve Lee (@SteveL-MSFT) Window size really seems to be the issue here:

    image

    You can see there that I ran it once and no error was displayed while the host window was scaled to a small size. Then I expanded the window and ran it again and the error was rendered to the screen.

    I had no idea that had an impact on displaying the error!

    EDIT: I also confirmed the same issues exists in the VS Code integrated terminal if I squish it down really small.

    EDIT 2: It appears to also matter what the error's source is. For instance in your case you received an error that the command is unknown. If I remove the module and repro that, I get the error displayed regardless of window size. If I actually load the module so the command is available, then I only get an error if the window is large enough. Hopefully that helps a bit.

  6. krokofant commented on May 12, 2020

    @krokofant

    This seems to be the cause of errors not showing up in Azure Pipelines. The powershell task has been updated (not yet released it seems) to workaround the issue by explicitly setting $ErrorView to NormalView before any code is invoked.

  7. mattmcnabb commented on May 15, 2020

    @mattmcnabb
    Author

    Steve Lee (@SteveL-MSFT) I'm no longer able to reproduce this issue in PowerShell 7.0.1. I'm thinking maybe this was fixed with #11880?

  8. vexx32 commented on May 15, 2020

    @vexx32
    Collaborator

    Yep, seems to be the case. Glad it's sorted out!

    I'll close this one for now. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions