Giter Site home page Giter Site logo

Comments (6)

twada avatar twada commented on June 20, 2024

@jamestalmage Yeah, that's exactly what I'm thinking of.

from empower.

twada avatar twada commented on June 20, 2024

Let me explain a history behind the code.

Also, instead of re-throwing an error (which messes with the existing stack trace needlessly). You could just use serialize-error attach the context, and throw.

I've implemented the same strategy, but some of old browsers (including PhantomJS) have strange behavior. When I rethrow Errors after attaching some props, the props disappear.

try {
    try {
        ...
    } catch (e) {
        e.foo = 'bar';
        throw e;
    }
} catch (e) {
    assert(e.foo === 'bar');  // Error on old PhantomJS
}

refactor(empower): always re-instantiate AssertionError on rethrow ยท power-assert-js/empower@997da24

However, I found that the attached props are remaining on current PhantomJS.
So I can just attach and rethrow the original Error now.

It's a delightful discovery. Thanks!

from empower.

jamestalmage avatar jamestalmage commented on June 20, 2024

@twada - serialize-error actually does not create an error. It creates a plain old javascript object with deep copies of the Errors properties. An Error object does not survive JSON.stringify() very well. Especially assertion errors that have circular references.

Check the unit tests for all it does.

For use outside AVA, throwing non-errors is probably a bad idea. Could you maybe split most of the functionality into another module? empower-core or something. It should take a copyAssertion callback. empower can continue to copy the Assertion the way you've been doing it here, and we can make a custom version that uses serialize-error to make the copy.

from empower.

twada avatar twada commented on June 20, 2024

@jamestalmage

Could you maybe split most of the functionality into another module? empower-core or something. It should take a copyAssertion callback.

Yeah I'm working on that !

from empower.

twada avatar twada commented on June 20, 2024

Update: Now in a beta stage

from empower.

twada avatar twada commented on June 20, 2024

Close this issue since twada/empower-core is going on.

from empower.

Related Issues (6)

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.