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.

bug(function-tree): TypeError: Cannot read property 'color' of null

See original GitHub issue

Given:

const FunctionTree = require('function-tree')
const NodeDebuggerProvider = require('function-tree/providers/NodeDebugger')
const ContextProvider = require('function-tree/providers/Context')
const express = require("express");

const app = express().get("/", (req, res) => res.send("howdy!"));

const run = new FunctionTree([
  // Verified this is the problem
  NodeDebuggerProvider({ colors: { app: "green" } }),
  ContextProvider({ app })
]);

const startServer = (context) => new Promise((resolve, reject) => {
  const { app, path } = context;

  const server = app.listen(3000, (error) => {
    if (!path) {
      return console.log(`Listening on 3000...`);
    }

    return error ? reject(path.error({ error })) : resolve(path.success({ server }));
  });
});

const stopServer = (context) => new Promise((resolve, reject) => {
  const { app, input, path } = context;

  input.server.close((error) => {
    return error ? reject(path.error({ error })) : resolve(path.success());
  });
});

run([ startServer, {
  success: [stopServer, {
    success: [startServer],
  }],
}]);

An error in NodeDebuggerProvider occurs:

❯ node index.js
 => new Promise
{}
app.listen 3000
 => new Promise
{"server":{"domain":null,"_events":{},"_eventsCount":2,"_connections":0,"_handle":{"bytesRead":0,"_externalStream":{},"fd":13,"reading":false,"owner":"[CIRCULAR]","onread":null,"writeQueueSize":0},"_usingSlaves":false,"_slaves":[],"_unref":false,"allowHalfOpen":true,"pauseOnConnect":false,"httpAl...
events.js:160
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'color' of null
    at send (/Users/Eric/tmp/f-express/node_modules/function-tree/providers/NodeDebugger.js:86:27)
    at /Users/Eric/tmp/f-express/node_modules/function-tree/providers/NodeDebugger.js:145:5
    at /Users/Eric/tmp/f-express/node_modules/function-tree/src/index.js:119:9
    at Array.reduce (native)
    at FunctionTreeExecution.createContext (/Users/Eric/tmp/f-express/node_modules/function-tree/src/index.js:116:48)
    at FunctionTreeExecution.runFunction (/Users/Eric/tmp/f-express/node_modules/function-tree/src/index.js:40:24)
    at runBranch (/Users/Eric/tmp/f-express/node_modules/function-tree/src/executeTree.js:41:7)
    at /Users/Eric/tmp/f-express/node_modules/function-tree/src/executeTree.js:18:13
    at /Users/Eric/tmp/f-express/node_modules/function-tree/src/index.js:58:11
    at process._tickCallback (internal/process/next_tick.js:103:7)

Converting NodeDebuggerProvider.js at Line 82 from:

    if (isExistingFunction) {

      var data = prevFunction.data[prevFunction.data.length - 1]
      var args = data ? data.args || [] : []

to

    if (isExistingFunction) {

      var data = prevFunction.data[prevFunction.data.length - 1] || {};
      var args = data ? data.args || [] : []

resolves it, but returns undefined, which is clearly not desirable:

❯ node index.js
 => new Promise
{}
app.listen 3000
 => new Promise
{"server":{"domain":null,"_events":{},"_eventsCount":2,"_connections":0,"_handle":{"bytesRead":0,"_externalStream":{},"fd":13,"reading":false,"owner":"[CIRCULAR]","onread":null,"writeQueueSize":0},"_usingSlaves":false,"_slaves":[],"_unref":false,"allowHalfOpen":true,"pauseOnConnect":false,"httpAl...
undefined
app.listen 3000
Listening on 3000...

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ericclemmonscommented, Nov 17, 2016

Hmmm, I don’t know how to go about a test for that since this was a run-time, integration-style bug.

1reaction
Guriacommented, Nov 15, 2016

Sorry guys for delay. Now when repo has a great setup, could one of you prepare PR with failing test?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'style' of null at ...
Whenever i seperately run the following code document.querySelector('h1').style.color = colors[Math.round(Math.random()*6)]; it works as it ...
Read more >
Uncaught TypeError: Cannot read property 'color' of null #27
App started and error appeared. Atom Version: 0.208.0 System: Mac OS X ... Uncaught TypeError: Cannot read property 'color' of null #27.
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
getElementById('stuff') returns null. So adding .value will cause the error. You are trying to access a DOM element before the DOM is ready....
Read more >
Keep getting error message "Cannot read property '1' of null"
When it loops over to the colors array to apply the next color, it will not work since it does not exist. listItems[1].style.color...
Read more >
Uncaught TypeError: Cannot read property 'id' of null
Odd thing is, first it's all fine, preview, publish, all works. Next day I come back to the exact same file and I...
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