218 return query.exec();
219 }
220 })
221 .then(row => {222 if (!row)
223 reject({ fn: 'NotFound', message: 'Vulnerability not found' });
224 else {
208 var query = Vulnerability.findById(vulnIdMerge);
209 query
210 .exec()
211 .then(row => {212 if (!row)
213 reject({ fn: 'NotFound', message: 'Vulnerability not found' });
214 else {
108 var query = Vulnerability.findByIdAndUpdate(vulnerabilityId, vulnerability);
109 query
110 .exec()
111 .then(row => {112 if (!row)
113 reject({ fn: 'NotFound', message: 'Vulnerability not found' });
114 else {
776 query.select('findings');
777 query
778 .exec()
779 .then(row => { 780 if (!row)
781 throw {
782 fn: 'NotFound',
754 return row.save({ validateBeforeSave: false }); // Disable schema validation since scope changed from Array to String
755 }
756 })
757 .then(() => { 758 if (sortAuto)
759 return Audit.updateSortFindings(isAdmin, auditId, userId, null);
760 else resolve('Audit Finding updated successfully');
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}