Bluebird throwing exception at source code - node.js

I am using bluebirdjs for nodejs application. It throws an exception from its source code.
Line : try {throw new Error(); } catch (e) {ret.lastLineError = e;}
Path : bluebird/js/release/util.js
Line : 374
This exception seems unnecessary to me. It only throws exception. Is it rational to delete this line?
Same code also exists inside async.js at line 3.

In IE an Error object will not have a .stack property unless it goes a through try catch. The .stack property is needed to see which line and file the code is in.
ret.lastLineError = new Error() would therefore only work in firefox and chrome

Related

NodeJS assert does not throw passed error

I have just started using NodeJS's assert Module, and, given that I have understood it correctly, I can pass a custom error instance that should be thrown instead of an AssertionError if the assertion fails.
I.e., the first line in the following code throws an AssertionError and the second line throws an Error:
const assert = require('assert');
assert(false);
assert(false, new Error('abc'));
However, on my system, this does not seem to work. I have the following code:
try {
assert(false, new Error('abc'));
} catch (error) {
console.log(error.constructor.name);
}
and the Output I get is 'AssertionError'. Interestingly, when I try to do the same thing using the REPL, the output is the expected 'Error'.
I use NodeJS v15.8.0 in an alpine Docker container.

vorpal .validate throwing error

I have a vorpal command that looks like this:
I am running version 1.9.5.
const vorpal = require('vorpal')()
vorpal
.command('temp [dev]')
.validate(function() {
return false
})
.action(function() {
...
})
vorpal.parse(process.argv)
And when i run pnt temp in my terminal I get this error thrown:
/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:169
throw new Error(err);
^
Error: null
at EventEmitter.<anonymous> (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:169:17)
at callback (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:830:22)
at /Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:961:7
at EventEmitter._commandSetCallback (/Users/samm/Sites/pnt/node_modules/vorpal/dist/session.js:446:5)
at EventEmitter.session.completeCommand (/Users/samm/Sites/pnt/node_modules/vorpal/dist/session.js:526:12)
at onCompletion (/Users/samm/Sites/pnt/node_modules/vorpal/dist/session.js:456:10)
at EventEmitter.session.execCommandSet (/Users/samm/Sites/p nt/node_modules/vorpal/dist/session.js:471:5)
at EventEmitter.vorpal._exec (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:960:18)
at EventEmitter.vorpal._execQueueItem (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:751:17)
at EventEmitter.vorpal._queueHandler (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:735:10)
I admit that this is looking ugly, and they will probably fix this in future versions, but this looks like the correct behaviour.
Returning false or a string from .validate should throw an error, as this means that you don't accept the arguments. If you return a string that string will be shown to the user (return "I don't want no scrubs.").
So from the code that you posted this is the correct behaviour.
If you like the errormessage from .validate to be different, I recommend you post an issue on vorpal's issue tracker. (Even though I can see you have already done that).

node.js path.rename() throws error despite working correctly

I am renaming files and are getting some weird behavior. It both works and throws an error.
This is the code:
var fs = require('fs');
var file = {
rename: function(from, to){
fs.rename(from, to, function (err) {
if (err) throw err;
console.log("[i] Renamed " + from + " to " + to);
});
}
}
When using it I get this console output:
main.js:1153 [i] Renamed E:\images\oldName.jpg to E:\images\newName.jpg
main.js:1152 Uncaught Error: ENOENT: no such file or directory, rename 'E:\images\oldName.jpg' -> 'E:\images\newName.jpg'
main.js:1152 (anonymous function)
fs.js:73 (anonymous function)
I don't understand what the problem is. The file is renamed anyway.
Also, it doesn't happen if the file is moved to another folder.
Why is this happening and do I have to worry about it?
The function is being called twice. That means the second time it's called the file is no longer there, leading to the 'no such file or directory'. I notice you're using windows which might also be part of the issue. Are you by any chance using fs.watch to call this function? You might be seeing an inherit problem in fs.watch under Windows duplicating events. If so, there's some example code that might help you.

[TypeError: Object # has no method 'replace']

First off all. I'm not posting questions about the error reason. This suddenly appeared when running an node.js app where after executing the query this error was received. I just want to know how to find the line in the source code where this error appears. How to set node to display extended info in errors like this?
So the error would be displayed like:
[TypeError: Object # has no method 'replace'] Test.js 123:98
put line 123 in try and catch the error
try{
// line 123
} catch(e){
throw e;
}
so it will print the stack of the error

Error "Unable to get property 'normalize' of undefined or null reference" in require.js with text.js

I'm making my first attempt at using the text.js plugin (v2.0.12) for require.js (v2.1.15). I've had require working well up to this point, however, when I attempt to resolve a text dependency, I get two errors. The first error is Unable to get property 'normalize' of undefined or null reference [require.js, Line: 955] then, after the allotted time, I'll get a timeout error for the html file I'm attempting to load. The focus of this cry for help is the former error.
One curious observation I've noticed is that if I resolve the text module without declaring a file, there is no error. However, when I add the file path e.g. text!path/file, the error is triggered.
Additionally, I noticed that the load timeout error references the text module with _unnormalized2 appended. Not sure if that's to be expected but I thought is odd. Any help would be greatly appreciated!
Here's the block of code which errors:
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
if (this.map.unnormalized) {
//Normalize the ID if the plugin allows it.
if (plugin.normalize) { // error occurs here (line 955)
name = plugin.normalize(name, function (name) {
return normalize(name, parentName, true);
}) || '';
}
// ...
}
Ok, it turns out to have been a self-sabotage! I was creating a shortcut definition for the text module for which I left out the factory method. So, instead of
define('text', ['Scripts/text'], function(text) { return text; });
I had:
define('text', ['Scripts/text']);
Nothing to do with text.js whatsoever.

Resources