439 let stockData = await gotData.json();
440 if (!gotData.ok) {
441 message.reply(embed.error("There was an error getting stock info.", `${stockData.cod || gotData.status}: ${stockData.message || gotData.statusText}`));
442 return;443 }
444 if (!stockData) {
445 message.reply(embed.error(`${args[0]} was not found.`, "ERR_EMPTY_RESPONSE"));
227 switch (command) {
228 case "amiadmin":
229 if (!message.member) return message.reply("Trick question.");
230 if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("you're not admin!");231 else return message.reply("you are admin!");
232 case "testdm":
233 message.author.send("Looks like the DM worked! You can send commands in here.")
226 console.count("Command");
227 switch (command) {
228 case "amiadmin":
229 if (!message.member) return message.reply("Trick question.");230 if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("you're not admin!");
231 else return message.reply("you are admin!");
232 case "testdm":
425 if (usedStocksRecently.has(message.author.id)) {
426 message.reply(embed.error(`You need to wait ${timeout / 1000} seconds before asking for stocks again.`, "ERR_RATE_LIMIT", "Slow down!"));
427 } else {
428 (async () => {429 if (!stocksEnabled) {
430 message.reply(embed.error("Stock lookup isn't currently working. Sorry about that.", "ERR_NO_STOCK_KEY"));
431 return null;
481 message.reply(embed.error("You didn't include any arguments. Re-run the command with the summoner name."));
482 return;
483 }
484 (async () => {485 let reg = "NA";
486
487 if (args[1]) {
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;
}