The-Quill / SE-Chat-Terminal

SE chat in Terminal
MIT License
12 stars 1 forks source link

No rooms in domain causes undefined error #26

Closed The-Quill closed 8 years ago

The-Quill commented 8 years ago

A domain should try to connect to the initial room, however, it can't as there's no rooms.

I should probably write a config sample guide to avoid errors of this sort.

vihanb commented 8 years ago
var start = function() {
  const promises = Object.keys(config.room_domains).map(function(domainName) {
    var domain = config.room_domains[domainName];
    domainName = domainNameFixer(domainName);
    var firstDomainName = Object.keys(domain.rooms)[0];
    var domainRooms = JSON.parse(JSON.stringify(domain.rooms));
    delete domainRooms[firstDomainName];
    if (firstDomainName) return connectDomainRooms(domainName, domain.rooms[firstDomainName], domainRooms);
    else return false;
  })
  return Promise.all(promises)
};

does that fix it?

vihanb commented 8 years ago

nevermind

The-Quill commented 8 years ago

It would work, but you have to return a Promise IIRC.

vihanb commented 8 years ago
if (domain.rooms.length === 0){
    return new Promise()
    .then(function(){})
    .error(function(){});
}

can be golfed to:

if (domain.rooms.length === 0)
    return new Promise()
     .then(function(){})
     .error(function(){});

which can be golfed to:

if (domain.rooms.length)
    return new Promise()
    .then(a=function(){})
    .error(a);

which can be golfed to:

if (domain.rooms.length)
    return new Promise()
    .then(function(){})
    .error(function(){});
The-Quill commented 8 years ago

No. This isn't PPCG.

vihanb commented 8 years ago

please

The-Quill commented 8 years ago

no. I'm using brackets.

The-Quill commented 8 years ago

From a duplicate:

vihanb commented If I have a site with 0 rooms. It still throws an error:

/Users/vihan/Downloads/SE-Chat-Terminal-master-4/chat_modules/core.js:121
    var initialRoomId = initialRoom.room_id;
                                   ^
TypeError: Cannot read property 'room_id' of undefined
    at connectDomainRooms (/Users/vihan/Downloads/SE-Chat-Terminal-master-4/chat_modules/core.js:121:36)
    at /Users/vihan/Downloads/SE-Chat-Terminal-master-4/chat_modules/core.js:225:16
    at Array.map (native)
    at Object.start (/Users/vihan/Downloads/SE-Chat-Terminal-master-4/chat_modules/core.js:214:55)
    at Object.<anonymous> (/Users/vihan/Downloads/SE-Chat-Terminal-master-4/start.js:3:6)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)
    at node.js:974:3