Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-3443

PowerShell - PowerShell Manager host will propagate user code exceptions in a misleading way

    XMLWordPrintable

Details

      • Error messages should clearly identify user code is at fault, and not the module
      • There should be a new test to demonstrate this behavior
    • 2
    • Windows 2016-09-07

    Description

      The puppet-chocolatey community module uses reflection to modify the current PowerShell host. However, it was a bit fragile, generated exceptions, and propagated them through PowerShell module 2.0.

      While the fix was put in at https://github.com/chocolatey/puppet-chocolatey/commit/166ae968dd455a9cf94cf3d88050f9a973c449ce, this still raises an interesting issue for executing user code.

      Our code should be a little more defensive / explanatory, when the call to EndInvoke over user code is executed. As it stood, the error message generated was a bit misleading:

      Debug: STDERR: Exception calling "EndInvoke" with "1" argument(s): "You cannot call a method on a null-valued expression."

      The exception was thrown from:
      https://github.com/puppetlabs/puppetlabs-powershell/blob/a0f3cc7498730df9ccde98c1bea40920b0a3643a/lib/puppet_x/templates/invoke_ps_command.erb#L428

      The module can do a better job of identifying the problem is with user code (which may involve parsing the exceptions, etc).

      This might also be a good time to do a simple cleanup of the repetitive $ps.Commands.Clear() calls that showed up in https://github.com/puppetlabs/puppetlabs-powershell/commit/9b785f0c149d59b7a91f1efb48f0bc8235f031c9 - these seem unnecessary, and the commit only briefly mentions "command pollution" without any explanation.

      Attachments

        Issue Links

          Activity

            People

              erick Erick Banks
              ethan Ethan Brown
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support