Skip to content

Commit

Permalink
Small fix to catch JSON stringify errors within Writer.publish
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Peter committed Jul 25, 2017
1 parent f1488c9 commit 5bb59f0
Show file tree
Hide file tree
Showing 5 changed files with 3,130 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ The writer is connected to `nsqd`
## Release History
|Version|Date|Description|
|:--:|:--:|:--|
|0.1.3|2017-07-25|Small fix to catch JSON stringify errors within `Writer.publish`|
|0.1.2|2016-07-22|Fixed a stupid error with the host config of the writer|
|0.1.1|2016-07-19|Removed debugging output|
|0.1.0|2016-07-15|Updated dependencies [Issue#2](https://github.com/mpneuried/nsq-logger/issues/2) and optimized activate [Issue#3](https://github.com/mpneuried/nsq-logger/issues/3)|
Expand Down
2 changes: 1 addition & 1 deletion _src/test/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe "----- nsq-logger TESTS -----", ->
return
return

after: ( done )->
after ( done )->
testServers.stop( done )
return

Expand Down
9 changes: 8 additions & 1 deletion _src/writer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ class NsqWriter extends require( "./basic" )
if _isString( data )
_data = data
else
_data = JSON.stringify(data)
try
_data = JSON.stringify(data)
catch _err
if cb?
cb( _err )
else
@error( "stringify data for topic `#{topic}`", _err )
return

@client.publish @nsAdd( topic ), _data, ( err )=>
if err
Expand Down
Loading

0 comments on commit 5bb59f0

Please sign in to comment.