Skip to content

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

Merged
Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:module-error
Mar 8, 2021
Merged

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

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Feb 27, 2021

Copy link
Copy Markdown
Member

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 Ilya (iSazonov) Feb 27, 2021
@iSazonov Ilya (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

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

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

Staffan Gustafsson (@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

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

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.

Steve Lee (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

Ilya (@iSazonov) are you ok to merge this?

@iSazonov

Copy link
Copy Markdown
Collaborator

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

@iSazonov

Copy link
Copy Markdown
Collaborator

The CI has the problem in all PRs.

@JustinGrote

Copy link
Copy Markdown
Contributor

Ilya (@iSazonov) Steve Lee (@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

Justin Grote (@JustinGrote) Could you please create a test for scenario you mean?

@JustinGrote

Copy link
Copy Markdown
Contributor

Ilya (@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

Justin Grote (@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
Steve Lee (SteveL-MSFT) deleted the module-error branch March 11, 2021 18:48
@JustinGrote

Copy link
Copy Markdown
Contributor

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

@ghost

Copy link
Copy Markdown

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

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
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