Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'createPattern' of null #19

Open
gauravsheel opened this issue Nov 16, 2017 · 2 comments
Open

TypeError: Cannot read property 'createPattern' of null #19

gauravsheel opened this issue Nov 16, 2017 · 2 comments

Comments

@gauravsheel
Copy link

Apologies if I have overlooked something or this has been discussed before.

The async patterns.createPattern method returns exception. Node version used is 8.9.0 (including other versions on runKit). The code sample on github/memz page doesn't work for me as well.

Example code run :

`// define grok pattern string
var p = '%{IP:client} \[%{TIMESTAMP_ISO8601:timestamp}\] "%{WORD:method} %{URIHOST:site}%{URIPATHPARAM:url}" %{INT:code} %{INT:request} %{INT:response} - %{NUMBER:took} \[%{DATA:cache}\] "%{DATA:mtag}" "%{DATA:agent}"';
// define test input string
var str = '203.35.135.165 [2016-03-15T12:42:04+11:00] "GET memz.co/cloud/" 304 962 0 - 0.003 [MISS] "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"';

// asynchronously load default grop patterns
require('node-grok').loadDefault(function (patterns) {
// create new anonymous grok pattern
var pattern = patterns.createPattern(p);
// parse test string
pattern.parse(str, function (err, obj) {
// output result object
console.log(obj);
});
});`

## error returned --
var pattern = patterns.createPattern(p);
^

TypeError: Cannot read property 'createPattern' of null
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/tmp.js:9:28
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/node-grok/lib/index.js:232:24
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/async/lib/async.js:726:13
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/async/lib/async.js:52:16
at done (/Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/async/lib/async.js:246:17)
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/async/lib/async.js:44:16
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/async/lib/async.js:723:17
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/async/lib/async.js:167:37
at /Users/gauravsheel/workfiles/web-work/tools/ngrok/node_modules/node-grok/lib/index.js:183:20
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

@juansmartenit
Copy link

Same issue here

@horacimacias
Copy link

horacimacias commented Jan 10, 2018

the callback specified in the readme is missing the error parameter.
The API description is correct (Callback receives patterns collection filled in with default templates: function(err, patterns)) but the sample code is not right as it's missing the error argument.

I had the same issue, just run the code as follows:

require('node-grok').loadDefault(function (err, patterns) {
console.log('patterns is ', patterns);
var pattern = patterns.createPattern(p);
pattern.parse(str, function (err, obj) {
console.log(obj);
});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants