question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

else statement returns still emits a return a value error

See original GitHub issue

The error each then() should return a value is reported even though the .then always returns a promise in the code below.

Apparently the logic for following return values can’t evaluate an else clause

    return oracle.getPrices(c)
    .then(function(p) {
        if (p.price != 0) {
            return p.price.toNumber() / 1e6;
        } else {
            // XXX unavoidable race
            return 200;
        }
    });  

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xjamundxcommented, Apr 8, 2016

right because I personally prefer the no-else-return rule, so in my case I’d still do the return 200 at the root level of the function.

Yeah totally valid bug though, solution is tricky to enforce properly.

We could check that there’s any return inside of a then function. For example:

.then(function(p) {
    if (p < 10) {
        return p * 1000;
    }
})

But then it obviously misses cases like this where the root of the function isn’t covered, but to some extent that is covered by consistent-return.

What do you think? Would you be able to try to make the code change?

0reactions
xjamundxcommented, May 12, 2016

ahh thanks for the note @scottnonnenberg I’ll try to look at this…in the meantime you may be abe to do something like this:

var dates
try { dates = parseWithDates(text) }
catch (e) { data = undefined }
return [response, dates]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correct a #VALUE! error in the IF function
If a function's syntax is not constructed correctly, it can return the #VALUE! error. Solution: Make sure you are constructing the syntax properly....
Read more >
How to fix inconsistent return statement in python?
I am new to python and i have this project I am working on a small project with two functions where the first...
Read more >
if / else errors - learn how to fix these - Codecademy
In the particular code example above, if the program execution has reached the else statement it means that: a < b returned false...
Read more >
RxJs Error Handling: Complete Practical Guide
As we can see, this HTTP stream emits only one value, and then it completes, which means that no errors occurred.
Read more >
Exceptions and Error Handling, C++ FAQ - Standard C++
The commonly used alternative to try / catch / throw is to return a return code (sometimes called an error code) that the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found