Skip to content

Commit

Permalink
fixed error handling on invalid arguments/params;
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Peter committed Jun 27, 2016
1 parent e714ac8 commit 2b90c26
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
13 changes: 10 additions & 3 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
module.exports = (grunt) ->

_testEnv = {}
if process.env.GLOBAL?
_testEnv.global = 1

# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON('package.json')
watch:
module:
files: ["_src/**/*.coffee"]
tasks: [ "coffee:base" ]
test:
files: ["_src/**/*.coffee"]
tasks: [ "coffee:base", "mochacli:main" ]

coffee:
base:
Expand Down Expand Up @@ -50,13 +58,13 @@ module.exports = (grunt) ->
grunt.loadNpmTasks "grunt-contrib-clean"
grunt.loadNpmTasks "grunt-mocha-cli"
grunt.loadNpmTasks "grunt-include-replace"
grunt.loadNpmTasks "grunt-docker"

# just a hack until this issue has been fixed: https://github.com/yeoman/grunt-regarde/issues/3
grunt.option('force', not grunt.option('force'))

# ALIAS TASKS
grunt.registerTask "w", "watch"
grunt.registerTask "w", "watch:module"
grunt.registerTask "wt", "watch:test"
grunt.registerTask "b", "build"
grunt.registerTask "t", "test"
grunt.registerTask "default", "build"
Expand All @@ -65,4 +73,3 @@ module.exports = (grunt) ->

# build the project
grunt.registerTask "build", [ "clear", "coffee:base", "includereplace" ]
grunt.registerTask "build-dev", [ "clear", "coffee:base", "docs", "test" ]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ get the current queue attributes and stats
rsmq stats [global-options]
```

#### `count`

get the message count of a queue

```sh
rsmq stats [global-options]
```

#### `listqueues` *short:* `ls`

List all queues within the namespace
Expand Down Expand Up @@ -131,6 +139,7 @@ configurate your client. This makes it possible to redefine the defaults of the
## Release History
|Version|Date|Description|
|:--:|:--:|:--|
|0.1.3|2016-06-27|fixed error handling on invalid arguments/params; removed generated code docs|
|0.1.2|2016-05-06|updated dependencies and dev environment|
|0.1.1|2015-03-03|first working version|
|0.0.1|2015-02-23|Initial commit|
Expand Down
29 changes: 23 additions & 6 deletions _src/lib/_rsmq.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class RSMQCli extends require( "mpbasic" )()
## constructor
###
constructor: ( options )->
_cnf = cnf.read( options.group )
if options?.group?.length
_cnf = cnf.read( options.group )
else
_cnf = cnf.read()
super( @extend( {}, _cnf, options ) )
@ready = false

Expand Down Expand Up @@ -78,6 +81,7 @@ class RSMQCli extends require( "mpbasic" )()
_send: ( messages, cb )=>
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )
return

afns = []
for msg in messages
Expand All @@ -100,7 +104,8 @@ class RSMQCli extends require( "mpbasic" )()
_create: ( cb )=>
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )

return

_args =
qname: @config.qname
vt: @config.vt or 30
Expand Down Expand Up @@ -128,12 +133,15 @@ class RSMQCli extends require( "mpbasic" )()
_visibility: ( msgid, vt, cb )=>
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )
return

if not msgid?.length
@_handleError( cb, "EINVALIDMSGID" )
return

if not vt? or isNaN( parseInt( vt, 10 ) )
@_handleError( cb, "EINVALIDVT" )
return

_args =
qname: @config.qname
Expand All @@ -146,12 +154,15 @@ class RSMQCli extends require( "mpbasic" )()
_attributes: ( _name, _value, cb )=>
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )
return

if not _name?.length or _name not in _attributeNames
@_handleError( cb, "EINVALIDATTRNAME" )
return

if not _value? or isNaN( parseInt( _value, 10 ) )
@_handleError( cb, "EINVALIDVT" )
return

_args =
qname: @config.qname
Expand All @@ -170,6 +181,7 @@ class RSMQCli extends require( "mpbasic" )()
[ onlycount ] = args
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )
return

_args =
qname: @config.qname
Expand All @@ -180,17 +192,19 @@ class RSMQCli extends require( "mpbasic" )()
return
if onlycount
cb( null, stats.msgs )
else
cb( null, JSON.stringify( stats ) )
return
cb( null, JSON.stringify( stats ) )
return
return

_delete: ( ids, cb )=>
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )

return

if not ids?.length
@_handleError( cb, "EINVALIDMSGIDS" )
return

afns = []
for id in ids
Expand All @@ -217,6 +231,7 @@ class RSMQCli extends require( "mpbasic" )()
_receive: ( cb )=>
if not @config.qname?.length
@_handleError( cb, "EMISSINGQNAME" )
return

_args =
qname: @config.qname
Expand All @@ -230,7 +245,9 @@ class RSMQCli extends require( "mpbasic" )()

quit: =>
clearTimeout( @wait4Connection ) if @wait4Connection?
@rsmq.redis.quit()
process.nextTick =>
@rsmq.redis.quit()
return
return

ERRORS: =>
Expand Down
2 changes: 1 addition & 1 deletion _src/lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cli
final = ( fnEnd )->
return ( err, results )->
if err
process.stderr.write( err.name + " : " + err.message )
process.stderr.write( err.name + " : " + err.message + "\n" )
else if _isObject( results )
process.stdout.write( JSON.stringify( results, 1, 2 ) )
else if _isString( results )
Expand Down
11 changes: 10 additions & 1 deletion _src/test/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ describe "----- rsmq-cli TESTS -----", ->
done()
return
return


it "get the queue count without the qname", ( done )->
call "count", ( err, result )->
Expand Down Expand Up @@ -467,4 +466,14 @@ describe "----- rsmq-cli TESTS -----", ->
return
return
return

describe 'Error Tests', ->
it "invalid create call", ( done )->
call "create", "abc", ( err, result )->
should.exist( err )
err.should.startWith( "EMISSINGQNAME" )
done()
return
return
return
return
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rsmq-cli",
"version": "0.1.2",
"version": "0.1.3",
"description": "A RSMQ terminal client",
"keywords": [ "rsmq", "redis", "cli", "terminal", "queue", "tool" ],
"homepage": "https://github.com/mpneuried/rsmq-cli",
Expand Down Expand Up @@ -34,13 +34,12 @@
"rsmq": "./bin/rsmq.js"
},
"devDependencies": {
"should": "8.x",
"should": "9.x",
"grunt": "1.0.x",
"grunt-contrib-watch": "1.x",
"grunt-contrib-coffee": "1.x",
"grunt-include-replace": "4.x",
"grunt-mocha-cli": "2.x",
"grunt-docker": "0.0.x",
"grunt-contrib-clean": "1.0.0"
}
}

0 comments on commit 2b90c26

Please sign in to comment.