Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConciseView error view mangles ParseException child classes with custom message #21469

Closed
5 tasks done
MatejKafka opened this issue Apr 13, 2024 · 4 comments
Closed
5 tasks done
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-By Design The reported behavior is by design. WG-Interactive-Console the console experience

Comments

@MatejKafka
Copy link

MatejKafka commented Apr 13, 2024

Prerequisites

Steps to reproduce

The implementation of ConciseView has special handling for rendering parser errors: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs#L1223

However, the code assumes that anything with CategoryInfo equal to ParserError is a ParseException and assumes that the format of the error message exactly matches the Message property of a ParseException.

In my code, I'm parsing custom PowerShell data files and throwing an exception class inheriting from ParseException, with added source position metadata in the error message. This results in confusing error messages when the exception is rendered using ConciseView.

I would prefer if the special rendering was only triggered for ParseException, and not for subclasses.

Expected behavior

Import-Pog: At D:\_\Pog\data\manifests\VS Code\.template\pog.psd1:27 char:137
+ … hePath"\s*:\s*)"([a-z][A-Z]+)"', ("`$1" + (ConvertTo-Json $CachePath)
+                                                                        ~
Missing closing ')' in expression.

Actual behavior

# no context, very hard for callers to understand where does the syntax error come from
Import-Pog: Missing closing ')' in expression.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0-preview.2
PSEdition                      Core
GitCommitId                    7.5.0-preview.2
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@MatejKafka MatejKafka added the Needs-Triage The issue is new and needs to be triaged by a work group. label Apr 13, 2024
@SteveL-MSFT SteveL-MSFT added the WG-Interactive-Console the console experience label Apr 15, 2024
@SteveL-MSFT
Copy link
Member

There was previously discussion on abstracting errors for module so it doesn't show internal details. Seems like you have a valid case to bubble up the error and provide more details. I think the question for the WG is how to enable this scenario. For example, do we want to make it opt-in for modules (like adding a special TypeName that can be used by conciseview).

@SteveL-MSFT SteveL-MSFT added the WG-NeedsReview Needs a review by the labeled Working Group label Apr 15, 2024
@StevenBucher98 StevenBucher98 added Resolution-By Design The reported behavior is by design. and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Apr 24, 2024
@sdwheeler sdwheeler added Issue-Enhancement the issue is more of a feature request than a bug Resolution-Declined The proposed feature is declined. and removed WG-NeedsReview Needs a review by the labeled Working Group Resolution-Declined The proposed feature is declined. labels Apr 24, 2024
@sdwheeler
Copy link
Collaborator

The working group discussed this issue. We understand the scenario but there are other ways to resolve your problem.

The class ParseException is used for to display parse errors in PowerShell syntax. There are existing scenarios where folks inherit ParseException but still generate ParseErrors that PowerShell can display. We would recommend not inheriting ParseException if this is not the behavior you are looking for.

Copy link
Contributor

This issue has been marked as by-design and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Copy link
Contributor

microsoft-github-policy-service bot commented Apr 25, 2024

📣 Hey @MatejKafka, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-By Design The reported behavior is by design. WG-Interactive-Console the console experience
Projects
None yet
Development

No branches or pull requests

4 participants