UnhandledPromiseRejectionWarning while starting code while sharding - javascript

I am trying to run my index.js file which runs my bot.js file. When I did node index.js, I got this error. Index.js is sharding my bot.js file (discord.js)
(node:7284) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_DIED]: Shard 0's process exited before its Client became ready.
at Shard.onDeath (C:\Users\Sochum\Desktop\BobloxBot\node_modules\discord.js\src\sharding\Shard.js:158:16)
at Object.onceWrapper (events.js:422:26)
at Shard.emit (events.js:315:20)
at Shard._handleExit (C:\Users\Sochum\Desktop\BobloxBot\node_modules\discord.js\src\sharding\Shard.js:384:10)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
(node:7284) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 7)
It doesn't actually say what the error is. Here is my index.js code:
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', {
totalShards:4,
token: "#",
})
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();
Here is my bot.js file code
https://pastebin.com/RW8abmKP
I am not sure why I am getting this error, but It might have something to do with the code starting in bot.js
new EconomyClient().start(require(`./config`).token, './commands', './index');

The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.

Related

IPFSAccessController.save ERROR: Error: Deprecated, use .toString()

i'm only trying to launch the exemple of the app kit OrbitDB which is :
import OrbitDB from "orbit-db";
import IPFS from "ipfs";
async function main () {
// Create IPFS instance
const ipfsOptions = { repo : './ipfs', }
const ipfs = await IPFS.create(ipfsOptions)
// Create OrbitDB instance
const orbitdb = await OrbitDB.createInstance(ipfs)
// Create database instance
const db = await orbitdb.keyvalue('ipfs_db')
}
main()
you can find it here : https://github.com/dappkit/aviondb#using-nodejs
but the problem is when i launch it, i got these errors :
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/12D3KooWM7D9NdMhtxyiWiKH4XVpuZW5oDu9MbWxFmEzLsG9UynM
Swarm listening on /ip4/192.168.1.53/tcp/4002/p2p/12D3KooWM7D9NdMhtxyiWiKH4XVpuZW5oDu9MbWxFmEzLsG9UynM
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/12D3KooWM7D9NdMhtxyiWiKH4XVpuZW5oDu9MbWxFmEzLsG9UynM
IPFSAccessController.save ERROR: Error: Deprecated, use .toString()
at CID.get toBaseEncodedString [as toBaseEncodedString] (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/multiformats/cjs/src/cid.js:94:11)
at Object.writeCbor [as write] (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db-access-controllers/node_modules/orbit-db-io/index.js:62:14)
at async IPFSAccessController.save (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db-access-controllers/src/ipfs-access-controller.js:46:13)
at async Function.create (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db-access-controllers/src/access-controllers.js:68:20)
at async OrbitDB._determineAddress (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db/src/OrbitDB.js:331:37)
(node:8397) UnhandledPromiseRejectionWarning: Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded
at undefinedEncoder (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/#ipld/dag-cbor/cjs/index.js:47:9)
at objectToTokens (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:175:20)
at Object (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:149:9)
at objectToTokens (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:184:10)
at Object (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:149:9)
at objectToTokens (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:184:10)
at encodeCustom (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:214:18)
at Object.encode (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:236:10)
at Object.encode (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/#ipld/dag-cbor/cjs/index.js:85:41)
at put (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/ipfs-core/src/components/dag/put.js:35:25)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8397) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:8397) [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.
i seriously don't know what to do, i tried to clear the cache, to delete node_modules and package-lock.json, and do a npm install, but nothing changed, i got the same error, do you have any idea to fix this ?
This error clearly points to an incompatibility between IPFS and OrbitDB.
The latest version of js-ipfs that OrbitDB v0.26.1 supports is 0.55.4.
You should change the ipfs (or ipfs-core) version in your package.json to ^0.55.4.
Note: The upcoming OrbitDB v0.27, will support the latest IPFS version.

I'm having a problem with a node js project, my server wont respond and will throw me an error [duplicate]

This question already has answers here:
MongooseError - Operation `users.findOne()` buffering timed out after 10000ms
(17 answers)
Closed 1 year ago.
My js file wont respond and it will trow me this error in the console wich i don't understand:
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Backend server is running
Connected to MONGODB
(node:5282) UnhandledPromiseRejectionWarning: MongooseError: Operation
`users.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/home/francesco/Desktop/Projects/Social Network/NODE-REST-
API/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149:23)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5282) 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(). To terminate the node
process on unhandled promise rejection, use the CLI flag `--unhandled-
rejections=strict` (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5282) [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.
This is the code of the module (btw dont mind but th "ok" its for testing.
const router = require("express").Router();
const User = require("../models/User")
//REGISTER
router.get("/register", async (req,res)=>{
const user = await new User({
username:"john",
email:"john#gmail.com",
password:"123456"
})
await user.save();
res.send("ok");
});
module.exports = router
the syntax is right, needed to format it for containing on the "code" on the question.
Thanks in advance, Francesco
You are trying to call the model without even establishing a connection with the database. You need to use async/await with connect() or createConnection().

How can I solve login error on discord.js [duplicate]

This question already has answers here:
Why am I getting a ReferenceError: AbortController is not defined in Discord.js v13?
(3 answers)
Closed 1 year ago.
const {Client, Intents} = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.login(token);
I have this code, every time i try to run it returns me the same error:
(node:13284) UnhandledPromiseRejectionWarning: ReferenceError:
AbortController is not defined
at RequestHandler.execute (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:172:15)
at RequestHandler.execute (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:176:19)
at RequestHandler.push (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:50:25)
at async WebSocketManager.connect (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\client\websocket\WebSocketManager.js:128:9)
at async Client.login (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\client\Client.js:245:7)
(Use node --trace-warnings ... to show where the warning was
created) (node:13284) 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(). To terminate the node
process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).
(rejection id: 2) (node:13284) [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.
Dont know how to fix it. I tried and investigate on the documentation but cant find the solution.
I've added this line to my code to find the error:
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
Getting this:
{ code: 500, method: 'get', path: '/gateway/bot', requestData:
{ json: undefined, files: [] } }
The AbortController package was introduced in Node.js v16 (?). So you need to upgrade your Node.js version. Discord.js v13 requires you to use Node.js v16 and higher as stated in their documentation.
Depending on your operating system, you can either install 64bits or 32bits version of Node.js. Head over to the official website and download 16.8.x (Current, Latest Features) Windows installer.
After installation, verify the version by typing node -v in your console.

Error trying to do search for records matching criteria with MongoDB

I am taking a training course, on Udemy, and it had backend code already written, as the course is purely about frontend development. It uses a very simple MongoDB database that I created. I determined that MongoDB version 4.0.10 is installed on my computer, in case that's relevant. When trying to perform a query for matching records, I get the following error:
UnhandledPromiseRejectionWarning: MongoError: FieldPath field names may not start with '$'.
at MessageStream.messageHandler (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\connection.js:268:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at TLSSocket.ondata (internal/streams/readable.js:719:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
(node:51960) 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(). To
terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
After looking into the backend code, I found the following code that is being used to perform the query/search, and I did notice that there are $ symbols in various places.
Post.search = function(searchTerm) {
return new Promise(async (resolve, reject) => {
if (typeof(searchTerm) == "string") {
let posts = await Post.reusablePostQuery([
{$match: {$text: {$search: searchTerm}}},
{$sort: {score: {$meta: "textScore"}}}
])
resolve(posts)
} else {
reject()
}
})
}
What exactly is wrong and how do I fix it?
Identical error here. Searching from react using axios in the main app-very simple(supposed to be). It's indicative that in my case when trying to search- "open search mode" from react", mongodb server crashes with mentioned error:
f:\PrgsReact\SimplePost\backend-api\node_modules\mongodb\lib\cmap\connection.js:268
callback(new MongoError(document));
MongoError: FieldPath field names may not start with '$'.
etc..
I'm tried to change npm ver of mongodb and axios inter alia. Thanks.

How to resolve MongoDb UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT cluster0.3zwxl.mongodb.net?

I am able to start the server but cannot able to run the web app as localhost getting the below error
Server started on port 3000
(node:13052) UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT cluster0.3zwxl.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19)
(node:13052) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:13052) [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.
Here is my url
mongoose.connect("mongodb+srv://xxxxxxxx:vikas#cluster0.3zwxl.mongodb.net/xxxxxx",{useNewUrlParser:true,useUnifiedTopology: true});
Moreover the webapp is not loading and getting "This site can’t be reached"
I was also facing the same issue today itself.. and i found some of the solutions mentioned below:
Changing the DNS
Adding current IP to whitelist section of your mongodb
Connecting with the same network that you've configured with
Solution No. 3 worked for me... as soon as i connected to my network which i had configured with i got console Connected to database... and as soon as i change my network again i got the error
you can see the image when i connected back to previous network it was working but when i changed my network i got the error
I had fixed my issue
mongoose.connect("mongodb+srv://xxxxxxxx:xxxxxxxx#cluster0.3zwxl.mongodb.net/xxxxxx?retryWrites=true&w=majority",{useNewUrlParser:true,useUnifiedTopology: true});
mongoose.connection.on("connected",()=>{
console.log("Mongoose connected");
})
better approach for multiple connections for future use
const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
console.log("MONGODB: Default Connection Established");
} catch (error) {
console.log(error);
process.exit(1);
}
}
connectDB();

Categories