Code Monkey home page Code Monkey logo

Comments (3)

alx9r avatar alx9r commented on September 24, 2024

Implementation ideas:

  1. Rewrite the .ScriptStackTrace property with a string that omits a bunch of the stack trace.
  2. Catch the exception at lowest point in the call stack that is inside ZeroDSC, and somehow re-throw that same exception at the highest point in the call stack.
  3. Change the way [ConfigStep] objects are set up such that the call stack between Invoke-ConfigStep and the underlying resource is minimized.

from zerodsc.

alx9r avatar alx9r commented on September 24, 2024

(1) is complicated by .ScriptStackTrace being a read-only property.

try
{
    throw
}
catch
{
    $_.ScriptStackTrace = 'new trace'
}

results in

'ScriptStackTrace' is a ReadOnly property.
At C:\Users\un1\Desktop\test.ps1:7 char:5
+     $_.ScriptStackTrace = 'new trace'
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

from zerodsc.

alx9r avatar alx9r commented on September 24, 2024

It doesn't seem like (2) would work because .ScriptStackTrace is populated when the exception is first thrown. So catching and re-throwing doesn't change its contents. For example,

function f1 { throw 'exception in f1' }
function f2 { try { f1 } catch { return $_ } }
function f3 { $e = f2; return $e }
function f4 { $e = f3; throw $e }

Describe 'delayed re-throw' {
    It 'test' {
        f4
    }
}

results in

Describing delayed re-throw
 [-] test 18ms
   RuntimeException: exception in f1
   at f1, C:\Users\un1\Desktop\test.ps1: line 1
   at f2, C:\Users\un1\Desktop\test.ps1: line 2
   at f3, C:\Users\un1\Desktop\test.ps1: line 3
   at f4, C:\Users\un1\Desktop\test.ps1: line 4
   at <ScriptBlock>, C:\Users\un1\Desktop\test.ps1: line 8

from zerodsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.