negezor / vk-io

Modern VK API SDK for Node.js
https://npm.im/vk-io
MIT License
548 stars 85 forks source link

TypeError: Cannot destructure property `apiLimit` of 'undefined' #151

Closed Saiv46 closed 5 years ago

Saiv46 commented 5 years ago

What version of vk-io are you using?

What version of Node.js are you using?

What did you do?

Added logging system, one middleware and started pooling. Then triggered the "group_join" event when bot polling started.

What did you expect to happen?

Event payload should be passed to middlewares or at least throw a VKError.

What was the actual result?

An error happens in the async cycle so the main process got terminated every time.

Logs

When debugging, the updates.vk (referenced at this.vk) is becoming "[Circular]" when handling polling update and its options property is undefined.

C:\nodejs\node.exe --inspect-brk=41124 app.js
Debugger listening on ws://127.0.0.1:41124/5a104bd7-e88a-4c2e-ba6a-1f7340c4c8f8
For help, see: https://nodejs.org/en/docs/inspector
winston:create-logger Define prototype method for "error"
winston:create-logger Define prototype method for "warn"
winston:create-logger Define prototype method for "info"
winston:create-logger Define prototype method for "http"
winston:create-logger Define prototype method for "verbose"
winston:create-logger Define prototype method for "debug"
winston:create-logger Define prototype method for "silly"
winston:create-logger Define prototype method for "error"
winston:create-logger Define prototype method for "warn"
winston:create-logger Define prototype method for "info"
winston:create-logger Define prototype method for "http"
winston:create-logger Define prototype method for "verbose"
winston:create-logger Define prototype method for "debug"
winston:create-logger Define prototype method for "silly"
silly: Logger ready!
silly: Pre-processing middleware ready!
2019-04-16T10:32:07.853Z vk-io:api http --> groups.getLongPollServer
2019-04-16T10:32:08.403Z vk-io:api http <-- groups.getLongPollServer 525ms
2019-04-16T10:32:08.407Z vk-io:updates http -->
2019-04-16T10:32:08.410Z vk-io:updates Bot Polling started
info: Ready in {"durationMs":2184}
silly: VK bot on @clubXXXXXXXXX ready!
2019-04-16T10:32:33.846Z vk-io:updates http <-- 200
2019-04-16T10:32:33.850Z vk-io:updates http -->
2019-04-16T10:32:57.214Z vk-io:updates http <-- 200
2019-04-16T10:32:57.215Z vk-io:updates webhook update { type: 'group_join',
  object: { user_id: 393055078, join_type: 'join' },
  group_id: XXXXXXXXX }
2019-04-16T10:32:57.235Z vk-io:updates http -->
Handle polling update error: TypeError: Cannot destructure property `apiLimit` of 'undefined' or 'null'.
    at API.worker (f:\Projects\notify\node_modules\vk-io\lib\index.js:1011:17)
    at API.callWithRequest (f:\Projects\notify\node_modules\vk-io\lib\index.js:988:10)
    at API.enqueue (f:\Projects\notify\node_modules\vk-io\lib\index.js:994:17)
    at Proxy.params (f:\Projects\notify\node_modules\vk-io\lib\index.js:961:145)
    at JSON.stringify (<anonymous>)
    at stringify (f:\Projects\notify\node_modules\fast-safe-stringify\index.js:11:18)
    at Format.module.exports.format [as transform] (f:\Projects\notify\node_modules\logform\json.js:24:19)
    at DerivedLogger._transform (f:\Projects\notify\node_modules\winston\lib\winston\logger.js:305:29)
    at DerivedLogger.Transform._read (f:\Projects\notify\node_modules\readable-stream\lib\_stream_transform.js:177:10)
    at DerivedLogger.Transform._write (f:\Projects\notify\node_modules\readable-stream\lib\_stream_transform.js:164:83)
2019-04-16T10:32:57.245Z vk-io:updates longpoll error TypeError: Cannot read property 'agent' of undefined
    at Updates.fetchUpdates (f:\Projects\notify\node_modules\vk-io\lib\index.js:6904:30)
    at Updates.startFetchLoop (f:\Projects\notify\node_modules\vk-io\lib\index.js:6869:20)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2204) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property `pollingWait` of 'undefined' or 'null'.
    at Updates.startFetchLoop (f:\Projects\notify\node_modules\vk-io\lib\index.js:6876:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:2204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Debugger attached.
Waiting for the debugger to disconnect...
negezor commented 5 years ago

This is only possible with:

vk.options = undefined;

Can I see the initialization code?

Saiv46 commented 5 years ago
/** LOGGER INIT */
const DEV = process.env.NODE_ENV !== "production";
const winston = require("winston");
const {LoggingWinston} = require("@google-cloud/logging-winston");
const logger = winston.createLogger({
    level: DEV ? "silly" : "info",
    exitOnError: !DEV,
    transports: DEV ? [
        new winston.transports.Console({
            format: winston.format.simple()
        })] : [ new LoggingWinston() ]
});
logger.silly("Logger ready!");
logger.profile("Ready in");
/** VK INIT */
const { VK } = require("vk-io");
const { updates, api } = new VK({
    language: "ru",
    token: process.env.TOKEN,
    pollingGroupId: +process.env.GROUPID,
    apiHeaders: {"User-Agent": "Google App Engine"}
});
//const  = vk;

As you can see, vk.options is not touched at all! And polling initializating fine.

negezor commented 5 years ago

I was unable to reproduce this behavior. Can you create a separate repository with this behavior?

negezor commented 5 years ago

There were no changes, so I’ll close this issue. Feel free to open it again.