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.

Actions break when returning null

See original GitHub issue

In app.js:77 hyperapp will crash if an action returns a value that is neither undefined nor typeof object (also for null). null.

Reason is that it tries to access result.then which is only possible for objects.

Also what should be the expected behavior if a function returns null? I used that in a previous version to get around return without any parameters. This lead me to discover this crash upon upgrading to v0.7.1.

E.g.

// abort if mode is `off`
if (mode.toLowerCase() === 'off') return
someFunctionCall()
// without semicolons this looks like it would return the next line
// similar to
const example = () =>
someFunctionCall()
// which would return the result of `someFunctionCall`
// just because you're aware that `return` terminates on newline doesn't mean that it doesn't look like it wouldn't/shouldn't

For now I’ll use undefined, but it’d be good to have a defined behavior for null and other primitives.

Maybe we should introduce environment-specific errors like React does? They’d be amazing for development and can just get stripped away in production environments. There could be an error or warning in the case of null etc.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
leeoniyacommented, Mar 12, 2017

plus you cannot redefine null, but you can redefine undefined in javascript (wtf, right?). if you want to explicitly test against undefined you have to use typeof x == "undefined". but == null should cover both cases since it will internally test against the built-in undefined as well as null. i use it everywhere internally in domvm, and it works well & is fast.

1reaction
FlorianWendelborncommented, Mar 12, 2017

@jbucaran That should work, yes. It’d lead to a defined behavior.

If the minifier supports it I’d suggest to use the more explicit result === null || result === undefined though, since it makes it obvious that the == is no mistake (it usually is).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking when a method returns null in the Eclipse debugger
I need to break and investigate when this method returns null. There are many paths and return statements. It is possible to break...
Read more >
Avoid returning null in your code - Mindful Codes
This time I am going to look into some possible solutions to avoid returning null in your code. In general, it ends with...
Read more >
Best Practices : Page Reference method return null
One use case for returning null is when an action should redirect, and is expected to according to it's name like you say,...
Read more >
RETURN NULL in my function find() completely breaks my ...
RETURN NULL in my function find() completely breaks my function. I have no idea why it returns NULL for everything when its added....
Read more >
Discosal: Null-conditional return · Issue #437 · dotnet/csharplang
yield break if you absolutely must. if (collection == null) throw new ArgumentNullException(nameof(collection)); foreach (int index in ...
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