Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: move mfs cmds and safer exit #1981

Merged
merged 13 commits into from
Aug 1, 2019
Merged

fix: move mfs cmds and safer exit #1981

merged 13 commits into from
Aug 1, 2019

Conversation

hugomrdias
Copy link
Member

@hugomrdias hugomrdias commented Apr 8, 2019

This PR moves mfs cli commands to parser.js to make them available for tests and also tweak a bit error handling.

@ghost ghost assigned hugomrdias Apr 8, 2019
@ghost ghost added the status/in-progress In progress label Apr 8, 2019
Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

src/cli/bin.js Outdated Show resolved Hide resolved
src/cli/bin.js Show resolved Hide resolved
Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - can we get CI green please?

@alanshaw
Copy link
Member

ping @hugomrdias - any chance you can get this one ready to merge?

hugomrdias and others added 4 commits July 19, 2019 11:53
This PR moves mfs cli commands to parser.js to make them available for tests and also add `signal-exit` to the cli to make forced exits safer.
Co-Authored-By: hugomrdias <[email protected]>
if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
console.error(`Please update your Node.js version to ${pkg.engines.node}`)
process.exit(1)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uncaughtException/unhandledRejection handlers and node version check need to be above the require statements as they were because any one of them could cause an error or use code that is not supported in the version of Node.js that the user is running.

process.once('unhandledRejection', (err) => {
print(err.message)
debug(err)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log these out as they were before? ...(maybe console.error not console.info?)

These unexpected errors aren't always easy to reproduce so getting hold of a stack trace after the fact could be difficult and time consuming. You'd have to run the command again in debug mode and somehow replicate the circumstances that trigger the error.

Users also rarely run in debug mode so won't see the stack either. That translates to it being more difficult for us to begin to debug if users open an issue with just an error message and not a stack trace.

It also makes it harder for users to self debug - users unfamiliar with the debug module need to figure out how to turn it on in order to get the stack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to do that it's better to just let them throw and remove the handlers all together

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2019-07-23 at 14 00 14

First is with:

process.on('uncaughtException', err => {
  console.error(err)
  process.exit(1)
})

...second is without.

Not much in it TBH. It's kinda nice to have the Node.js internal stack greyed out.

My main concern is having the stack logged for these unexpected errors and not behind a debug flag 😉

@@ -58,7 +58,7 @@ describe('config', () => runOnAndOff((thing) => {
})

it('set a config key with invalid json', () => {
return ipfs.fail('config foo {"bar:0} --json')
return ipfs.fail('config foo {"bar:0"} --json')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is meant to fail!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and still does!
if we don't close the quotes the stdin keeps open for manual input

})
}))
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite complicated, would it be better to just require the command and call the handler, passing in the mocks and asserting on the result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i know thats one of the things im gonna do next, do injection with https://github.com/yargs/yargs/blob/master/docs/api.md#parseargs-context-parsecallback

this will become just

it('should output formatted json string', async () => {
    const { data } = await cli.parse('id', {
      ipfs: {
        id: Promise.resolve({ id: 'id', publicKey: 'publicKey' })
      }
    })

    expect(data).to.eq('{\n  "id": "id",\n  "publicKey": "publicKey"\n}')
})

no spies, no mocks, no stubs just plain simple js

@hugomrdias hugomrdias requested a review from alanshaw July 24, 2019 14:55
@alanshaw alanshaw merged commit fee0141 into master Aug 1, 2019
@alanshaw alanshaw deleted the fix/fix-mfs-safer-exit branch August 1, 2019 16:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants