-
Notifications
You must be signed in to change notification settings - Fork 130
Update $ErrorView with simplified views for Error Messages #228
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
Merged
Merged
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
bafe2b2
Added RFC Error View
theJasonHelmick bdd3ee9
update RFC error view
theJasonHelmick dd58c11
Added shorter reference code
theJasonHelmick d3ed694
update alternate view
theJasonHelmick 5fd9c69
Added RFC Error View
theJasonHelmick 3dd0560
update RFC error view
theJasonHelmick a7d6a75
Added shorter reference code
theJasonHelmick 6faa7dc
update alternate view
theJasonHelmick c454366
updated comment due date on Error-View
theJasonHelmick fb60588
Update 1-Draft/RFC00XX-Update-Error-View.md
theJasonHelmick f4edfcd
review update for view name -simpleview
theJasonHelmick a6329e7
update to view name
theJasonHelmick 0641bb2
fix unresolved merge conflict
theJasonHelmick 8dabf42
Removed incorrect parameter -Oldest
theJasonHelmick 35ed896
errorview-removed unneeded parameters
theJasonHelmick 5cf273d
Errorview update to remove unneeded parameters
theJasonHelmick 07af6d2
Changed view name from Concise to SimpleView
theJasonHelmick da03165
Added WriteErrorLine clarification
theJasonHelmick 8cdd56a
Added example showing Inner exception
theJasonHelmick 1bc65b1
Merge to my master
theJasonHelmick 6de0c3e
updated normal and detailed view
theJasonHelmick 697327c
added image of new error view
theJasonHelmick d6f6af4
Added image of errorview and adjusted carets
theJasonHelmick 889cad4
Spelling correction
theJasonHelmick 9439d35
Updated graphic display of error messages
theJasonHelmick 51ec0f2
graphic update
theJasonHelmick 1f272cd
edits to Overview
theJasonHelmick a58d4e8
update $errorview to enum
theJasonHelmick 800f653
resolved conflict
theJasonHelmick ea14fcd
spelling corrections
theJasonHelmick 46b2382
update for a new pr
theJasonHelmick b2f46ca
update to reflect view changes
theJasonHelmick 0cef8c3
updated RFC Resolve-errorrecord definition
theJasonHelmick ec0b745
Corected typos
theJasonHelmick 493a3a7
Updated RFC with Prefix conditions
theJasonHelmick 8d0498e
update RFC to reflect new cmdlet name
theJasonHelmick 34a3a62
updated RFC with Concise view as default view
theJasonHelmick 3493c6b
Update RFC00XX-Update-Error-View.md
SteveL-MSFT 04559ed
updated image to reflect cuurent code
theJasonHelmick eaecab0
update to reflect implementation
theJasonHelmick a97cbfe
update to match implementation - remove carets
theJasonHelmick 0cfab18
update to correct readability flow
theJasonHelmick 07807c7
update messageposition property information
theJasonHelmick e6cf938
Prep RFC0048 - Updated Error View for merging
joeyaiello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
--- | ||
RFC: Update $ErrorView with simplified views for Error Messages | ||
Author: Jason Helmick | ||
Status: Draft | ||
Version: 0.0.0 | ||
Area: PowerShell | ||
Comments Due: 10/31/2019 | ||
--- | ||
|
||
# Update $ErrorView with simplified views for Error Messages | ||
|
||
When an error occurs in PowerShell, the customers on-screen error message experience currently | ||
provides a level of detail that obscures the exception message from being recognized and read by new | ||
or occasional PowerShell users. The addition of a simplified error view will improve both | ||
comprehension and troubleshooting experience. A new cmdlet `Get-Error` will provide | ||
complete detailed view of the fully qualified error when desired. | ||
|
||
## Motivation | ||
|
||
The on-screen experience, when receiving an error message, is controlled through the views | ||
NormalView (the default) and CategoryView. These are user selectable through the preference variable | ||
**$ErrorView**. This RFC describes Changing **$ErrorView** to an enumeration and adding one | ||
additional dynamic view to improve readability; 'ConciseView' | ||
|
||
- ConciseView - provides a concise error message suitable for new or occasional PowerShell users and | ||
a refactored view for advanced module builders. If the error is not from a script or parser error, | ||
then it's a single line error message. Otherwise, you get a multiline error message that contains | ||
the error, a pointer and error message showing where the error is in that line. If the terminal | ||
doesn't support Virtual Terminal, then vt100 color codes are not used. | ||
|
||
A comprehensive detailed view of the fully qualified error, including inner exceptions, will be | ||
provided by the `Get-Error` cmdlet. | ||
|
||
**$ErrorView** shall contain the original views for backward compatibility and to lessen this | ||
breaking change. The view list is as follows: | ||
|
||
- ConciseView | ||
- NormalView | ||
- CategoryView | ||
|
||
## Specification | ||
|
||
The proposal is to add one new view, 'ConciseView', to help improve error message comprehension. | ||
ConciseView will be the default view. For in-depth error object information, a new cmdlet | ||
'Get-Error' provides detailed error information. | ||
|
||
__Key Design Considerations__ | ||
|
||
1. To reduce confusion and improve debugging success for new and occasional users, error messages | ||
should call WriteErrorLine to produce a simplified message for interactive CLI users. | ||
|
||
- The error message will contain a prefix as described: | ||
|
||
- If the error is an Exception, it prefixes with Exception:. | ||
- If the error has InvocationInfo.MyCommand, it prefixes the command. | ||
- If the error has InvocationName, CategoryInfo.Category, or CategoryInfo.Reason, the message | ||
will prefix these. | ||
- Only if none of those exist does it actually use Error:. | ||
|
||
- Simplified error message syntax from 'Message'. (See graphic below) | ||
|
||
```powershell | ||
PS C:\> Get-Childitem -Path c:\notreal | ||
Get-Childitem: Cannot find path ‘C:\notreal’ because it does not exist | ||
``` | ||
|
||
2. To improve script debugging for advanced module builders and scripters, a refactored error view | ||
will be displayed. If the error is not from a script or parser error, then it's a single line | ||
error message. Otherwise, you get a multiline error message that contains the error and a pointer | ||
and error message showing where the error is in that line. | ||
|
||
- A new property **ErrorAccentColor** is added to support changing the accent color of the error | ||
message. If the terminal doesn't support Virtual Terminal, then vt100 color codes are not used. | ||
|
||
```powershell | ||
PS C:\> .\MyScript.ps1 | ||
Get-ChildItem: in /Users/Username/GitHub/Errorview/script.test.ps1 | ||
Line | | ||
15 | Get-ChildItem -Path c:\notreal | ||
| ^^^ Cannot find path 'C:\notreal' because it does not exist. | ||
* Help: Additional help information provided here | ||
``` | ||
|
||
- An example is in the image below: | ||
|
||
 | ||
|
||
3. A new cmdlet `Get-Error` will produce comprehensive detailed view of the fully qualified error, | ||
including nested inner exceptions. | ||
|
||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Rendering is recursive for nested objects for Exceptions, InvocationInfo, and Arrays otherwise it | ||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uses ToString(). | ||
- Members that are empty or null are not shown. | ||
- Indentation uses 4 spaces for nested objects | ||
- A new FormatAccentColor is introduced to highlight property names from their values. This can be | ||
used later to add accents to tables and list formatting. | ||
- Removed some commented out unneeded code from ConciseView. | ||
|
||
- `Get-Error` will provide the following: | ||
|
||
- Display the newest Error ($Error[0]) – default behavior | ||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Accept Pipeline input – support $error[1] | | ||
- Option for the Newest X errors in the session (This will be aliased with Last) | ||
|
||
- `Get-Error` syntax | ||
|
||
```powershell | ||
Get-Error [-InputObject <psobject>] [-Newest <Int32>] [-All] [<CommonParameters>] | ||
``` | ||
|
||
First parameter set | ||
|
||
- Newest | ||
|
||
+ Datatype: int32 | ||
+ specifies one or more of the newest errors to display | ||
+ Not required | ||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
__Example 1__ | ||
Error occurs in Interactive mode. Cmdlet displays details of the last error displayed | ||
|
||
```powershell | ||
PS C:\> Get-Childitem -Path c:\notreal | ||
Get-ChildItem: Cannot find path ‘C:\notreal’ because it does not exist | ||
|
||
PS C:\test> Get-Error | ||
|
||
**** Detailed message here **** | ||
``` | ||
|
||
__Example 2__ | ||
Error occurs in script, shows error from view 'Analytic', and then is piped | ||
from $error array to 'Get-Error' to display more details. | ||
|
||
```powershell | ||
PS C:\> .\MyScript.ps1 | ||
Get-ChildItem: in /Users/Username/GitHub/Errorview/script.test.ps1 | ||
| | ||
15 | Get-ChildItem -Path c:\notreal | ||
| ^^^ Cannot find path 'C:\notreal' because it does not exist. | ||
* Help: Additional help information provided here | ||
|
||
PS C:\> $error[0] | Get-Error | ||
|
||
**** Detailed message here **** | ||
``` | ||
|
||
__Example 3__ | ||
Display detailed error information for the most recent 3 errors. | ||
|
||
```powershell | ||
PS C:\> Get-Error -Newest 3 | ||
|
||
**** Detailed message here **** | ||
**** Detailed message here **** | ||
**** Detailed message here **** | ||
``` | ||
|
||
__Example 4__ | ||
Maintain the ErrorRecord object for additional pipeline operations | ||
|
||
```PowerShell | ||
PS C:\> Get-Error -Newest 3 | Select-String -Pattern 'MyFile.txt' | ||
|
||
**** Detailed message here **** | ||
``` | ||
|
||
## Alternate Proposals and Considerations | ||
|
||
__Alternative/additional view customization__ | ||
|
||
It is conceivable in the future to add extensibility for module builders, | ||
that they could supply their own diagnostic script for specific error customization. | ||
|
||
__Alternative single-line display__ | ||
|
||
```powershell | ||
<CommandName>:<Exception Message> | ||
get-item: Cannot find path ‘C:\blah’ because it does not exist: | ||
|
||
<CommandName>:<Exception Message>: <Position> | ||
get-item: Cannot find path ‘C:\blah’ because it does not exist: At line:1 char:1 | ||
|
||
<CommandName>:<Alias>:<Exception Message>: <Position> | ||
get-item: gi: Cannot find path ‘C:\blah’ because it does not exist: At line:1 char:1 | ||
|
||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ERROR:<Exception Message> | ||
ERROR: Cannot find path ‘C:\blah’ because it does not exist | ||
|
||
ERROR:<Exception Message>: <Position> | ||
ERROR: Cannot find path ‘C:\blah’ because it does not exist: At line:1 char:1 | ||
|
||
ERROR:<CommandName>:<Alias>:<Exception Message>: <Position> | ||
ERROR: get-item: gi: Cannot find path ‘C:\blah’ because it does not exist: At line:1 char:1 | ||
``` | ||
|
||
__Alternative color for all errors__ | ||
|
||
1. We could change the default error message color from the current RED foreground and BLACK background to ?. | ||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. Differentiating errors based on termination condition: terminating versus non-terminating | ||
is currently not intuitive. We are examining differentiating these conditions on the console. | ||
Example, adding a new property $host.PrivateData.NonTerminatingErrorForegroundColor ='Red'. | ||
For occasional customers, all error messages remain as color Red. For advanced customers, | ||
they can change non-terminating errors to another color to separate the error | ||
termination type in the console. | ||
|
||
__Alternative For Error, Warning, Verbose__ | ||
|
||
1. We could be more terse in our messages and increase consistency with verbose | ||
and warning messages by using a single letter to identify the message. | ||
|
||
Legend: V = Verbose, W = Warning, E = Error(non-terminating future), F = Fatal | ||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```powershell | ||
V: You are running your code - what could possibly go wrong. | ||
|
||
W: You are about to try something that probably will not work. | ||
|
||
E: Your something broke, but Im still running. At line:1 char:1 | ||
|
||
E: Your something broke, but Im still running. At line:1 char:1 | ||
|
||
E: Your something broke, but Im still running. At line:1 char:1 | ||
|
||
F: Now you really broke me. At line:1 char:1 | ||
|
||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.