Why a instance of TypeError has undefined e.fileName on node?
I'm throw a TypeError object, but in catch statement the error object has undefined lineNumber and fileName properties. I test the following code from MDN on nodejs v16:
try {
throw new TypeError('Hello', "someFile.js", 10)
} catch (e) {
console.log(e instanceof TypeError) // true
console.log(e.message) // "Hello"
console.log(e.name) // "TypeError"
console.log(e.fileName) // "someFile.js"
console.log(e.lineNumber) // 10
console.log(e.columnNumber) // 0
console.log(e.stack) // "@Scratchpad/2:2:9\n"
}```
but fileName and lineNumber still undefined.
do you know?
how many words do you know
See also questions close to this topic
-
Error message : MongoServerError: bad auth :Authentication failed
What is the reason behind this error? this code I am using to connect to DB.
const uri =`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASSWORD}@cluster0.xft2s.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;
-
In Mongo, If a document I'm saving "Prateek" then I don't want on the next create operation even the "prateek" or "praTEEK", etc is saved
//** If I'm adding a new document with the name: "India", then I don't want that the DB allow another name with the name: "INDIA", "india", "indIA", etc. I'm new and learning, help would be great!!**
// Controller
var Dinosaur = require('../models/dinosaurs'); //addDino module.exports.addDino = (req, res) => { var name = req.body.name; var type = req.body.type; var height = req.body.height; var weight = req.body.weight; var Period = req.body.Period; req.checkBody('name', 'Name is required').notEmpty(); var errors = req.validationErrors(); if (errors) return res.status(400).send({ message: 'Name is Required' }); else { let newDino = { name: name, type: type, height: height, weight: weight, Period: Period } Dinosaur.addDino(newDino, (err, result) => { if (err) { if (err.name) return res.status(409).send({ message: name + ' Already Exist' }); else if (err.url) return res.json({ status: false, error: { url: "Url already exist" }, message: err.url }); else return res.json(err, "Server Error"); } else { return res.status(200).send({ message: "Done" }); } }); } }
// Model
var mongoose = require('mongoose'); //dinosaur schema var DinosaurSchema = mongoose.Schema({ name: { type: String, unique: true }, type: { type: String }, height: { type: Number }, weight: { type: Number }, Period: { type: String } }); var Dinosaur = mongoose.model('dinosaur', DinosaurSchema); //add module.exports.addDino = (query, callback) => { Dinosaur.create(query, callback); }
// GetAll, Already Created a new document with the name "Brachiosaurus"
// > Create, a new create with the first letter lower case "brachiosaurus", Don't want it to be pushed.
- i am trying to run the node of ganache but getting this error
-
Converting PYODBC output into an int
Pulling data from a SQL query that gives me 1 number that is stored in a PYODBC row. I want to then add that number to another variable in the file. Pseudocode below -
prev = 5 cursor.execute("select statement") pulledNumber = cursor.fetchall() value = [row[2] for row in pulledNumber] final = prev + value
Getting a type error (list and int operation). Tried to cast the list to an int a few different ways but could not get it to work
-
TypeError: list indices must be integers
I'm trying to insert an item from one list to another and using an item from a list of numbers for the index but I'm getting this error even though I'm using integers for index numbers
and the other thing is that the same item is accepted as an index in the line just before the error
I even tried putting a number there just to test it but it gave me the same error
here's the code:
FoundLetters = ['p', 'l', '-', 'i', 'n'] MissingLetters = [] AllLetters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] def MissingCount(): for j in range(len(FoundLetters)): if FoundLetters[j] == '-': MissingLetters.append(int(j)) def iterate(): for i in range(len(AllLetters)): for i in AllLetters: FoundLetters.pop(MissingLetters[0]) FoundLetters.insert(MissingLetters[0], AllLetters[i]) MissingCount() iterate()
and this was the exact error:
Traceback (most recent call last): File "main.py", line 26, in <module> iterate() File "main.py", line 22, in iterate FoundLetters.insert(MissingLetters[0], AllLetters[i]) TypeError: list indices must be integers or slices, not str ** Process exited - Return Code: 1 ** Press Enter to exit terminal
-
Getting Error with UI for TikTok algorithm
So I basically made a algorithm which takes the users input and decided on a rank from 1-100 and puts it on a UI.
import tkinter, os, webbrowser, random #algorithm def tiktok_algorithm(share_count, like_count, comment_count, posts): if (share_count >= 10000 and like_count >= 5000 and posts >20 and comment_count.find("amazing")!= -1): rank = 1 elif (share_count >= 7000 and like_count >= 2000 and posts >25 and comment_count.find("amazing")!= -1): rank = random.randint(2,10) elif (share_count >= 6000 and like_count >= 1500 and posts >25 and comment_count.find("amazing")!= -1): rank = random.randint(11,20) elif (share_count >= 5000 and like_count >= 1300 and posts >20 and comment_count.find("amazing")!= -1): rank = random.randint(21,40) elif (share_count >= 4000 and like_count >= 1000 and posts >15 and comment_count.find("nice")!= -1): rank = random.randint(41,55) elif (share_count >= 3000 and like_count >= 500 and posts >11 and comment_count.find("cool")!= -1): rank = random.randint(56,70) elif (share_count >= 2000 and like_count >= 300 and posts >11 and comment_count.find("ok")!= -1): rank = random.randint(71,80) elif (share_count >= 1000 and like_count >= 150 and posts >11 and comment_count.find("ok")!= -1): rank = random.randint(81,90) elif (share_count >= 400 and like_count >= 100 and posts >11 and comment_count.find("ok")!= -1): rank = random.randint(91,97) else: rank = random.randint(98,100) return(rank) def calculate_ranking(): # read in the entry values like_count = int(likes_entry.get()) comment_count = comment_entry.get() posts = int(posts_entry.get()) shares = int(share_entry.get()) rank = tiktok_algorithm(like_count, comment_count, shares, posts) # "print" result to result label result_label.config(text="Your tiktok ranking is: " + str(rank)) root = tkinter.Tk() root.title("Magic Tiktok Algorithm") root.geometry("400x600") # likes likes_label = tkinter.Label(root, text="Number of Likes:") likes_label.pack() likes_entry = tkinter.Entry(root) likes_entry.pack() # comment comment_label = tkinter.Label(root, text="Comment:") comment_label.pack() comment_entry = tkinter.Entry(root) comment_entry.pack() #shares share_label = tkinter.Label(root, text="number of shares:") share_label.pack() share_entry = tkinter.Entry(root) share_entry.pack() #posts posts_label = tkinter.Label(root, text="Posts") posts_label.pack() posts_entry = tkinter.Entry(root) posts_entry.pack() #image img_path = os.path.dirname(__file__) + "\\tiktok-tricks-09.PNG" tiktok_image = tkinter.PhotoImage(file=img_path) resized_tiktok_img = tiktok_image.subsample(4,4) image_label = tkinter.Label(root, image=resized_tiktok_img) image_label.pack() # rank button rank_button = tkinter.Button(root, text="Get Ranking", command=calculate_ranking) rank_button.pack() # result result_label = tkinter.Label(root, text = "Your tiktok ranking is:") result_label.pack() # keep the UI running root.mainloop()
I keep getting this error, I have tried casting it to an integer, but it still doesn't work can anyone help: Do I need to change the top to str(tiktok_algorithm)
typeError: '>=' not supported between instances of 'str' and 'int'