X Tutup
Skip to content

Update Concise ErrorView to not show line information for errors from script module functions#14912

Merged
iSazonov merged 2 commits intoPowerShell:masterfrom
SteveL-MSFT:module-error
Mar 8, 2021
Merged

Update Concise ErrorView to not show line information for errors from script module functions#14912
iSazonov merged 2 commits intoPowerShell:masterfrom
SteveL-MSFT:module-error

Conversation

@SteveL-MSFT
Copy link
Copy Markdown
Member

@SteveL-MSFT SteveL-MSFT commented Feb 27, 2021

PR Summary

Currently, if a script module (like PowerShellGet v2) has an error, it shows internal information to the user which can be confusing. Change is to check if the invocation is from a .psm1 file and to not show the script line information. Developers of modules can still use Get-Error to get that information during development time.

Before:

PS> install-module lskjfd
Install-Package: /Users/steve/.local/share/powershell/Modules/PowerShellGet/2.2.5/PSModule.psm1:9711
Line |
9711 |  … talledPackages = PackageManagement\Install-Package @PSBoundParameters
     |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No match was found for the specified search criteria and module name 'lskjfd'. Try Get-PSRepository to see all available registered module repositories.

After:

PS> install-module lskjfd
Install-Package: No match was found for the specified search criteria and module name 'lskjfd'. Try Get-PSRepository to see all available registered module repositories.

(Note that the error record here is coming from Install-Package being used by Install-Module which is what gets returned by PowerShell)

PR Context

This was reported by users.

PR Checklist

@ghost ghost assigned iSazonov Feb 27, 2021
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 27, 2021
Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor comment.

@powercode
Copy link
Copy Markdown
Collaborator

Can we have another view that maintains the current functionality?

It works well as it is now.

@SteveL-MSFT
Copy link
Copy Markdown
Member Author

@powercode you can get the same (and more information) using Get-Error. It seems like a module should be an abstraction layer from the user. It could be configurable, but I also don't think we want tons of configuration that people don't use as I believe the current output of line information for a script module is really only useful to the author of the module.

@iSazonov
Copy link
Copy Markdown
Collaborator

Maybe it makes sense to add this in docs - $error vs ConciseView vs GetError.

@SteveL-MSFT
Copy link
Copy Markdown
Member Author

Static analysis failure is unrelated to this PR and being invested separately

Copy link
Copy Markdown
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Mar 1, 2021

Static analysis failure is unrelated to this PR and being invested separately

We could only run markdown tests (1) if CL-Doc label is present and (2) in nightly build.

SteveL-MSFT and others added 2 commits March 5, 2021 13:52
…ters/PowerShellCore_format_ps1xml.cs

Co-authored-by: Ilya <darpa@yandex.ru>
@SteveL-MSFT
Copy link
Copy Markdown
Member Author

@iSazonov are you ok to merge this?

@iSazonov iSazonov closed this Mar 6, 2021
@iSazonov iSazonov reopened this Mar 6, 2021
@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Mar 6, 2021

@SteveL-MSFT "PowerShell-CI-static-analysis (Secret Scan)" blocks merging :-( Could you please ask anybody in your team to look the issue?

@SteveL-MSFT SteveL-MSFT closed this Mar 8, 2021
@SteveL-MSFT SteveL-MSFT reopened this Mar 8, 2021
@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Mar 8, 2021

The CI has the problem in all PRs.

@JustinGrote
Copy link
Copy Markdown
Contributor

@iSazonov @SteveL-MSFT haven't had a chance to test but will this work for powershell modules that aren't a single .psm1 file? It's common for modules to be broken into "Private","Public", etc. folders and dot source in the files from there.

Maybe better to test for $myinvocation.mycommand.module.modulebase or something?

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Mar 9, 2021

@JustinGrote Could you please create a test for scenario you mean?

@JustinGrote
Copy link
Copy Markdown
Contributor

@iSazonov sure, fairly simple:

mymodule.psm1

. .\myfunction.ps1

myfunction.ps1

function myfunction {
  throw 'This should not have a line indicator in conciseview'
}

@SteveL-MSFT
Copy link
Copy Markdown
Member Author

@JustinGrote that still shows line information as the ErrorRecord shows the ps1 as the source and I don't see a way to map it to the psm1

@SteveL-MSFT SteveL-MSFT deleted the module-error branch March 11, 2021 18:48
@JustinGrote
Copy link
Copy Markdown
Contributor

@SteveL-MSFT How about if $myinv.MyCommand.Module.ModuleBase is present?

@ghost
Copy link
Copy Markdown

ghost commented Mar 16, 2021

🎉v7.2.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

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

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup