Skip to content

Commit

Permalink
fix: enhance err handling
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 7, 2024
1 parent 8a5ab95 commit 2291f50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webpod/ps",
"version": "0.0.0-beta.5",
"version": "0.0.0-beta.6",
"description": "A process lookup utility",
"publishConfig": {
"access": "public"
Expand Down
14 changes: 10 additions & 4 deletions src/main/ts/ps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ const _tree = ({
if (typeof opts === 'string' || typeof opts === 'number') {
return _tree({opts: {pid: opts}, cb, sync})
}
const handle = (all: TPsLookupEntry[]) => {
const onError = (err: any) => cb(err)
const onData = (all: TPsLookupEntry[]) => {
if (opts === undefined) return all

const {pid, recursive = false} = opts
Expand All @@ -184,10 +185,15 @@ const _tree = ({

try {
const all = _lookup({sync})
return sync ? handle(all) : all.then(handle)
return sync
? onData(all)
: all.then(onData, (err: any) => {
onError(err)
throw err
})
} catch (err) {
cb(err)
throw err
onError(err)
return Promise.reject(err)
}
}

Expand Down

0 comments on commit 2291f50

Please sign in to comment.