-
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
Changes from 31 commits
bafe2b2
bdd3ee9
dd58c11
d3ed694
5fd9c69
3dd0560
a7d6a75
6faa7dc
c454366
fb60588
f4edfcd
a6329e7
0641bb2
8dabf42
35ed896
5cf273d
07af6d2
da03165
8cdd56a
1bc65b1
6de0c3e
697327c
d6f6af4
889cad4
9439d35
51ec0f2
1f272cd
a58d4e8
800f653
ea14fcd
46b2382
b2f46ca
0cef8c3
ec0b745
493a3a7
8d0498e
34a3a62
3493c6b
04559ed
eaecab0
a97cbfe
0cfab18
07807c7
e6cf938
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
--- | ||
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 'Resolve-ErrorRecord' 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 three additional views | ||
to improve readability,'Message', 'Analytic', and 'Dynamic'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any examples of setting $ErrorView. Will $null and 'CategoryView' still be valid? In fact, after a few seconds of testing, it appears that Windows PS 5.1 does no validation of $ErrorView except to check whether it's 'CategoryView' (case-insensitive) before printing an error message. So it appears that there is some possibility of a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @essentialexch you are correct that there is currently no validation and that this change may be breaking. I will include some examples of setting the errorview, however I'm thinking it will be the same as today. $errorview = 'ViewName'. Also, I will be updating the view names to help lessen the impact of a breaking change. |
||
|
||
- Message - provides a concise error message suitable for new or occasional PowerShell users. | ||
- Analytic - provides a refactored form of NormalView | ||
- Dynamic - provides conditional switching between Message and Analytic. | ||
|
||
A comprehensive detailed view of the fully qualified error, including inner exceptions, | ||
will be provided by the `Resolve-ErrorRecord` cmdlet. | ||
|
||
'$ErrorView' shall contain the original views for backward compatibility and renamed | ||
to remove 'view' from the name. The view list is as follows: | ||
|
||
- Normal | ||
- Category | ||
- Message | ||
- Analytic | ||
- Dynamic | ||
|
||
## Specification | ||
|
||
The proposal is to add three new views to help improve error message comprehension | ||
based on user needs. For in-depth troubleshooting, a new cmdlet | ||
Resolve-ErrorRecord to provide 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 using view 'Message' | ||
and include the preface word “ERROR:” | ||
|
||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Simplified error message syntax from 'Message'. (See graphic below) | ||
|
||
```powershell | ||
PS C:\> Get-Childitem -Path c:\notreal | ||
ERROR: Cannot find path ‘C:\notreal’ because it does not exist | ||
``` | ||
|
||
2. To improve script debugging for advanced PowerShell users and scripters, | ||
a refactored error view 'Analytic' will be added displaying the error category, | ||
exception, code line and position, and include additional help for the user. | ||
|
||
```powershell | ||
PS C:\> .\MyScript.ps1 | ||
ERROR: ItemNotFoundException | ||
---> C:\GitHub\pri-errorview\RustTest\test.ps1 | ||
| | ||
15 | Get-ChildItem -Path c:\notreal | ||
| ^^^ Cannot find path 'C:\notreal' because it does not exist. | ||
| | ||
* Help: Additional help information provided here | ||
``` | ||
|
||
3. The 'Dynamic' view is a combination of the views 'message' and 'Analytic' for users working | ||
in the console that also run scripts. When the user is working Interactively in the CLI, | ||
they will receive errors in the view of 'Message'. When the user executes a script, | ||
errors will use the view 'Analytic'. | ||
|
||
- An example is in the image below: | ||
|
||
 | ||
|
||
4. A new cmdlet `Resolve-ErrorRecord` will produce comprehensive detailed | ||
view of the fully qualified error, including nested inner exceptions. | ||
|
||
theJasonHelmick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Resolve-ErrorRecord will provide the following: | ||
|
||
+ Display Last Error ($Error[0]) – default behavior | ||
+ Accept Pipeline input – support $error[1] | | ||
+ Option for the Newest X errors in the session | ||
|
||
- Resolve-ErrorRecord syntax | ||
|
||
```powershell | ||
Resolve-ErrorRecord [-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 | ||
ERROR: Cannot find path ‘C:\notreal’ because it does not exist | ||
|
||
PS C:\test> Resolve-ErrorRecord | ||
|
||
**** Detailed message here **** | ||
``` | ||
|
||
__Example 2__ | ||
Error occurs in script, shows error from view 'Analytic', and then is piped | ||
from $error array to 'Resolve-ErrorRecord' to display more details. | ||
|
||
```powershell | ||
PS C:\> .\MyScript.ps1 | ||
ERROR: ItemNotFoundException | ||
---> C:\GitHub\pri-errorview\RustTest\test.ps1 | ||
| | ||
15 | Get-ChildItem -Path c:\notreal | ||
| ^^^ Cannot find path 'C:\notreal' because it does not exist. | ||
| | ||
* Help: this is for additional help information | ||
|
||
PS C:\> $error[0] | Resolve-ErrorRecord | ||
|
||
**** Detailed message here **** | ||
``` | ||
|
||
__Example 3__ | ||
Display detailed error information for the most recent 3 errors. | ||
|
||
```powershell | ||
PS C:\> Resolve-ErrorRecord -Newest 3 | ||
|
||
**** Detailed message here **** | ||
**** Detailed message here **** | ||
**** Detailed message here **** | ||
``` | ||
|
||
## Alternate Proposals and Considerations | ||
|
||
__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 | ||
|
||
``` |
Uh oh!
There was an error while loading. Please reload this page.