Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console.log crashes fs-jetpack #29

Closed
black-snow opened this issue Aug 11, 2016 · 8 comments
Closed

Console.log crashes fs-jetpack #29

black-snow opened this issue Aug 11, 2016 · 8 comments

Comments

@black-snow
Copy link

black-snow commented Aug 11, 2016

console.log() on a fs-jetpack object (with abs/rel path) crashes my app.

var jetpack = require('fs-jetpack')
console.log(jetpack.cwd('/Users/Shared/whatever'))

A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: Path must be a string. Received 2
at assertPath (path.js:7:11)
at Object.resolve (path.js:1148:7)
at resolvePath (/Users/Shared/xxx/build/node_modules/fs-jetpack/lib/jetpack.js:49:21)
at Object.inspect (/Users/Shared/xxx/build/node_modules/fs-jetpack/lib/jetpack.js:149:27)
at formatValue (util.js:348:21)
at inspect (util.js:198:10)
at exports.format (util.js:75:24)
at Console.log (console.js:43:37)
at App. (/Users/Shared/xxx/build/background.js:466:13)
at emitOne (events.js:101:20)

fs-jetpack 0.9.2

@szwacz
Copy link
Owner

szwacz commented Aug 11, 2016

This one wins the WTF of the year for me. As you can see in the call stack console.log calls node util which looks for inspect function on any object it's inspecting and gues what... jetpack has this function as part of its API.
I couldn't belive in what I'm seeing but this is part of the official node API: https://nodejs.org/api/util.html#util_util_inspect_object_options

Don't know how to resolve this yet. Filed issue: nodejs/node#8071 to see what the almighty oracle will say.

@black-snow
Copy link
Author

black-snow commented Aug 12, 2016

I knew you'd like this one ;)

As a workaround we could check arguments.callee.caller and arguments.callee.caller.caller and maybe some more (or all) levels up to see if console.log is part of the trace and if it is just return what console.log expects (or nothing or toString).

Maybe with something like this:

function traceContains(needle, caller){
    if (!caller) return false
    return caller.name.contains(needle) || traceContains(caller.caller)
}

And then in inspect

if (traceContains('console', arguments.callee.caller) return somethingElse

@black-snow
Copy link
Author

This nodejs/node#8013 doesn't help, does it? Only took a quick glimpse.

@szwacz
Copy link
Owner

szwacz commented Aug 18, 2016

Kind of it is. This is not general solution, but anyone can do util.inspect.defaultOptions.customInspect = false in their project and then this problem should stop appearing.

That beaing said the easiest solution i see to fix this is to change the inspect method name to something else (unfortunately).

@black-snow
Copy link
Author

See nodejs/node#8174

@szwacz
Copy link
Owner

szwacz commented Sep 16, 2016

Yep, shipped with node 6.6.0. Will see what we can do here.

@black-snow
Copy link
Author

electron 1.4.0 ships w/ node 6.5.0, guess one of the next releases will be shipped w/ 6.6

Seems like all we have to do then is adding

const util = require('util')

// exported object
{
    // other API stuff
    util.inspect.custom = depth => 'maybe something useful here'
}

to jetpack.js.

@szwacz
Copy link
Owner

szwacz commented Nov 8, 2016

Jetpack v0.10.2 fixes this for node versions 6.6.0 or newer. No way to fix this in nodes older than that.

@szwacz szwacz closed this as completed Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants