cmd-try-catch description
This repository enables the ability to provide an array of commands with catch alternatives
The reason for this library
- I want to supply an array of commands that run in sequence, one after the other.
- If one of those commands fail then I want to try a series of catch commands.
- If the catch command fails, then move onto the next catch command. If that catch command succeeds then retry the original command.
- If the original command passes, then move onto the next top command, otherwise stop the entire sequence.
- If the original command fails again, then try any remaining untried catch commands. If there are no more catch commands, then stop the sequence.
- If all commands in the top list pass then return a success response.
Working example
package.json
"name": "interact-cmd-try-catch" "version": "1.0.0" "description": "" "main": "index.js" "scripts": "test": "echo \"Error: no test specified\" && exit 1" "start": "node index.js" "keywords": "author": "" "license": "ISC" "dependencies": "cmd-try-catch": "^2.0.0" "got": "^11.7.0"
index.js
const util = ;const sync = default;const got = ; const urlExistPromise = async { await }; const init = async { const objReturn = await ; console;} ;
outputs
npm run start > interact-cmd-try-catch@1.0.0 start c:\node_all\interact-cmd-try-catch> node index.js 1: func CATCH: docker run -d -p 80:80 --name mydocker docker/getting-started 1: funcobjReturn=
Providing a series of commands
example:
; ; ; /*getMapOfPasses = [ { complete: false, catch: [{ complete: false }, { complete: false }, { complete: true }, { complete: false }], }, { complete: null }];*/
You can supply either a cmd, function or promise - as long as they all return an objectSuccessOrError
as success
;
as error
;objSuccessOrError: IObjSuccessOrError =
example with func and promise
; ; ; ; ; ;
Real world usecase
The real benefit of this is usecases with something like docker, sql, bash scripts etc...
example usecase
;;; ;; ;; ;; ;describe'sync - usecase',;
Licence
This particular npm package I have provided MIT licence but please note that the dependencies of this package are variable. Some are Apache-2.0, BSD, BSD-2-Clause, BSD-3-Clause, BSD*, CC-BY-3.0, CC-BY-4.0, CC0-1.0, ISC, GPL, LGPL-3.0, MIT, WTFPL, UNLICENCED and so forth. They may change. Please be aware if using this under any commercial practice that it may break some of those licences and you hold your own liability.
This package uses those licences to provide working solution example. Please contact me if you wish to contract me and I maybe able to minimize this project to reduce any liability of those dependent licences.
Enjoy