steelbrain / steelbrain/node-ssh
Client.exec returns code null when command code is 0
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Description
When a command returns 0, node-ssh's exec always returns code: null.
It seems the faulty line is this one.
Here's a PR to fix that.
Even though this line is incorrect (the nullish coalescing operator should be used instead for example), it appears that it's not the only problem: channel.on('exit' is never emitted.
A simple way to reproduce it is with this (failing) test:
sshit('exec should return correct code', async function (t, port, client) {
await connectWithPassword(port, client)
const result = await client.exec('echo', ['$some', 'S\\Thing', '"Yo"'], { stream: 'both' })
t.is(result.stdout, '$some S\\Thing "Yo"')
t.is(result.code, 0)
})
Expected
result.code === 0
Actual
result.code === null
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/index.ts around line 361 and inspect how client.exec handles the channel.on('exit') event. Reproduce the issue with the failing 'exec should return correct code' test shown in the report; done means a successful echo command returns result.code === 0 and preserves the expected stdout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100