question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clean up stream messaging in Import-Module (specifically in ModuleCmdletBase)

See original GitHub issue

Summary of the new feature/enhancement

Import-Module is an example of how not to use streams in PowerShell. If the Verbose stream is not silenced with S.M.A.ActionPreference.SilentlyContinue or S.M.A.AP.Ignore, Import-Module outputs a ton of useless information to the Verbose stream. This does nothing more than create noise, and causes problems for anyone wanting to turn on verbose stream output to get to the bottom of real problems.

As a scripter, I want to see Progress messages for any stream output that is intended to show progress of a command, so that I don’t have progress messages cluttering up my log files.

As a scripter, I only want to see Verbose messages if they will help me troubleshoot a command that I invoked, so that I can get to the bottom of issues quickly without reading reams of irrelevant log messages.

As a command author, I only want to see Debug messages if they will help me diagnose why a command may be failing without using the debugger, so that I can get to the bottom of issues quickly without reading reams of irrelevant log messages.

Those three problem statements may not all apply here, but I wanted to call them out because the streams need to be used with intent, not just chosen arbitrarily to communicate some text message.

Proposed technical implementation details (optional)

Evaluate each of the Cmdlet.Write* invocations in https://github.com/PowerShell/PowerShell/blob/8f37cced709168f313a00b2e3ee7088495bbcd7a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs, and determine which stream should be used for each of the messages based on their intent, removing any messages that add no value whatsoever.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
mklement0commented, Sep 17, 2020

@vexx32, for Export-ModuleMember calls this is to be expected: they execute in PowerShell code that acts on $VerbosePreference set to Continue (either via an ancestral variable or via -Verbose); note that the messages are Export-ModuleMember’s, not Import-Module’s.

As such, this is simply another manifestation of the dynamic scoping problem discussed above, and something the workaround would eliminate.

1reaction
SeeminglySciencecommented, Sep 17, 2020

Okay so auto loading itself doesn’t trigger it, it’s the same preference propagation problem. The module I was testing with had logic in the psm1 to Import-Module a dll.

So technically it’s not triggering during auto load, but if you auto load a script module it looks like it anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Remove a Loaded Module - Scripting Blog
Summary: Bruce Payette talks about how to remove a module that has been loaded into your Windows PowerShell environment.
Read more >
pytest cannot import module while python can
I am a bit puzzled, it looks like this indicates an import error, but Python does it fine so why is there a...
Read more >
Untitled
... debug, and information streams. mentioned this issue Clean up stream messaging in Import-Module (specifically in ModuleCmdletBase) My thoughts on bash ...
Read more >
The CAD Import Module User's Guide
The CAD Import Module enables importing 3D designs from CAD files into your simulations. The import capabilities cover the most common 3D CAD...
Read more >
Modules - Learn You a Haskell for Great Good!
A Haskell program is a collection of modules where the main module loads up the other modules and then uses the functions defined...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found