René's URL Explorer Experiment


Title: Import-Module does not properly report errors to users · Issue #9855 · PowerShell/PowerShell · GitHub

Open Graph Title: Import-Module does not properly report errors to users · Issue #9855 · PowerShell/PowerShell

X Title: Import-Module does not properly report errors to users · Issue #9855 · PowerShell/PowerShell

Description: If you have a script module that generates a terminating error, the error message shown to users does not indicate that the error came from Import-Module. Instead it simply shows the script module internals. This is inappropriate for use...

Open Graph Description: If you have a script module that generates a terminating error, the error message shown to users does not indicate that the error came from Import-Module. Instead it simply shows the script module ...

X Description: If you have a script module that generates a terminating error, the error message shown to users does not indicate that the error came from Import-Module. Instead it simply shows the script module ...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/9855

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Import-Module does not properly report errors to users","articleBody":"If you have a script module that generates a terminating error, the error message shown to users does not indicate that the error came from `Import-Module`. Instead it simply shows the script module internals. This is inappropriate for users who may not have authored that script module.\r\n\r\nIf you have a function in a script module that generates a terminating error, and you invoke that function when the module is not loaded, the module will load, the terminating error will not be shown to end users at all, and the function will run. The suppression of the terminating error in this scenario needs to be corrected so that users see the error came from Import-Module which was implicitly invoked by invoking the command while auto-loading is enabled.\r\n\r\n**Note:** This issue is closely related to the problem with terminating error handling in PowerShell (for which [a collection of RFCs have been submitted as a PR](https://github.com/PowerShell/PowerShell-RFC/pull/187)). Terminating error handling aside, this issue focuses on how Import-Module does a poor job of reporting errors, sometimes not even reporting them at all.\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\n$moduleName = 'ModuleErrorHandlingTest'\r\n$modulePath = Join-Path -Path $([Environment]::GetFolderPath('MyDocuments')) -ChildPath PowerShell/Modules/${moduleName}\r\nNew-Item -Path $modulePath -ItemType Directory -Force \u003e $null\r\n$nmmParameters = @{\r\n    Path = \"${modulePath}/${moduleName}.psd1\"\r\n    RootModule = \"./${moduleName}.psm1\"\r\n    FunctionsToExport = @('Test-ErrorHandling')\r\n}\r\nNew-ModuleManifest @nmmParameters\r\n$scriptModulePath = Join-Path -Path $modulePath -ChildPath \"${moduleName}.psm1\"\r\nNew-Item -Path $scriptModulePath -ItemType File | Set-Content -Encoding UTF8 -Value @'\r\n    1/0 # Oops!\r\n    function Test-ErrorHandling {\r\n        [cmdletBinding()]\r\n        param()\r\n        'Error handling output'\r\n    }\r\n'@\r\n\r\n# This next command generates an error while loading the module, but the module still\r\n# loads, and the error message does not tell the user that it came from Import-Module\r\n# nor does it tell the user which module was being loaded when the error occurred.\r\nImport-Module $moduleName\r\nRemove-Module $moduleName\r\n\r\n# This next command generates an error while implicitly loading a module, but the error\r\n# is silenced and the module loads anyway so the end user has no idea that something\r\n# happened.\r\nTest-ErrorHandling\r\nRemove-Module $moduleName\r\nRemove-Item -LiteralPath $modulePath -Recurse -Force\r\n```\r\n\r\n# Expected behavior\r\n\r\nNote the differences in the actual error text that are shown in what should be expected when a module is loaded over what is actually shown below this code block.\r\n\r\n```none\r\nImport-Module: Unexpected error while importing ModuleErrorHandlingTest module. Attempted to divide by zero.\r\nAt line:23 char:1\r\n+ Import-Module $moduleName\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo          : NotSpecified: (:) [], RuntimeException\r\n+ FullyQualifiedErrorId : RuntimeException\r\n\r\nImport-Module: Unexpected error while implicitly importing ModuleErrorHandlingTest module. Attempted to divide by zero.\r\nAt line:29 char:1\r\n+ Test-ErrorHandling\r\n+ ~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo          : NotSpecified: (:) [], RuntimeException\r\n+ FullyQualifiedErrorId : RuntimeException\r\n\r\nError handling output\r\n```\r\n\r\n# Actual behavior\r\n\r\n```none\r\nAttempted to divide by zero.\r\nAt C:\\Users\\kirka\\OneDrive\\Documents\\PowerShell\\Modules\\ModuleErrorHandlingTest\\ModuleErrorHandlingTest.psm1:1 char:5\r\n+     1/0 # Oops!\r\n+     ~~~\r\n+ CategoryInfo          : NotSpecified: (:) [], RuntimeException\r\n+ FullyQualifiedErrorId : RuntimeException\r\n\r\nError handling output\r\n```\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable --\u003e\r\n\r\n```none\r\nName                           Value\r\n----                           -----\r\nPSVersion                      6.2.0\r\nPSEdition                      Core\r\nGitCommitId                    6.2.0\r\nOS                             Microsoft Windows 10.0.17763\r\nPlatform                       Win32NT\r\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion      2.3\r\nSerializationVersion           1.1.0.1\r\nWSManStackVersion              3.0\r\n```\r\n","author":{"url":"https://github.com/KirkMunro","@type":"Person","name":"KirkMunro"},"datePublished":"2019-06-07T19:50:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/9855/PowerShell/issues/9855"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:63507024-495e-7a2c-7fb8-54530d81bf3d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEE1E:3AE31F:8790945:B575A25:696E1F23
html-safe-nonce94afa32f8c1f6732ffbf66efd32abfb6b1a4943d0458e596bccac45d816292a9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTFFOjNBRTMxRjo4NzkwOTQ1OkI1NzVBMjU6Njk2RTFGMjMiLCJ2aXNpdG9yX2lkIjoiNDA5NjgwMjIxNDAxNTU0MTAyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb94f5868a70267b47384ea50a6db123f8b71063eaf04710157c980c631b4e05e
hovercard-subject-tagissue:453668547
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/9855/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ff898e173aca55cbc662efe98d312539f55f32bda020be4202f9725cd704b0ec/PowerShell/PowerShell/issues/9855
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ff898e173aca55cbc662efe98d312539f55f32bda020be4202f9725cd704b0ec/PowerShell/PowerShell/issues/9855
og:image:altIf you have a script module that generates a terminating error, the error message shown to users does not indicate that the error came from Import-Module. Instead it simply shows the script module ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameKirkMunro
hostnamegithub.com
expected-hostnamegithub.com
None113cc336e7105fbb9f2ee8beb67c6cc584d65fa66a8a1a5dd236ba66db174af7
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release1d23f8b0bc31294c6a73ba2f3adfdd8c7052ca1e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues/9855#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F9855
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F9855
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues/9855
Reloadhttps://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues/9855
Reloadhttps://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues/9855
PowerShell https://patch-diff.githubusercontent.com/PowerShell
PowerShellhttps://patch-diff.githubusercontent.com/PowerShell/PowerShell
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2FPowerShell%2FPowerShell
Fork 8.1k https://patch-diff.githubusercontent.com/login?return_to=%2FPowerShell%2FPowerShell
Star 51.2k https://patch-diff.githubusercontent.com/login?return_to=%2FPowerShell%2FPowerShell
Code https://patch-diff.githubusercontent.com/PowerShell/PowerShell
Issues 1.2k https://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues
Pull requests 212 https://patch-diff.githubusercontent.com/PowerShell/PowerShell/pulls
Discussions https://patch-diff.githubusercontent.com/PowerShell/PowerShell/discussions
Actions https://patch-diff.githubusercontent.com/PowerShell/PowerShell/actions
Projects 7 https://patch-diff.githubusercontent.com/PowerShell/PowerShell/projects
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/PowerShell/PowerShell/security
Please reload this pagehttps://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues/9855
Insights https://patch-diff.githubusercontent.com/PowerShell/PowerShell/pulse
Code https://patch-diff.githubusercontent.com/PowerShell/PowerShell
Issues https://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues
Pull requests https://patch-diff.githubusercontent.com/PowerShell/PowerShell/pulls
Discussions https://patch-diff.githubusercontent.com/PowerShell/PowerShell/discussions
Actions https://patch-diff.githubusercontent.com/PowerShell/PowerShell/actions
Projects https://patch-diff.githubusercontent.com/PowerShell/PowerShell/projects
Security https://patch-diff.githubusercontent.com/PowerShell/PowerShell/security
Insights https://patch-diff.githubusercontent.com/PowerShell/PowerShell/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/9855
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/9855
Import-Module does not properly report errors to usershttps://patch-diff.githubusercontent.com/PowerShell/PowerShell/issues/9855#top
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Cmdlets-Core%22
https://github.com/KirkMunro
https://github.com/KirkMunro
KirkMunrohttps://github.com/KirkMunro
on Jun 7, 2019https://github.com/PowerShell/PowerShell/issues/9855#issue-453668547
a collection of RFCs have been submitted as a PRhttps://github.com/PowerShell/PowerShell-RFC/pull/187
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Cmdlets-Core%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.