tvkitchen / countertop

The entry point for developers who want to set up a TV Kitchen.
https://tv.kitchen
GNU Lesser General Public License v3.0
6 stars 2 forks source link

generateTributaryMaps fails if an input is missing a mapped output #95

Closed slifty closed 4 years ago

slifty commented 4 years ago

Bug

Current Behavior

The generateTributaryMaps utility will take in a station and an output map, and figure out all of the combinations of those outputs that would be a valid tributary set.

Unfortunately, it breaks if that output map is missing a given input type (e.g. if the station expects foo but there are no outputs producing foo.

Input

Code, command line, or other relevant input / steps to reproduce the issue.

Appliance = generateMockAppliance(
  inputTypes: ['foo'],
  outputTypes: ['bar'],
)
station = new CountertopStation(Appliance)
outputMap = new Map()

generateTributaryMaps(station, outputMap) // throws an error

The error:

TypeError: Cannot read property 'filter' of undefined

      143 |     return inputTypes.reduce(
      144 |         (accumulator, type) => accumulator.flatMap(
    > 145 |             (tributarySet) => streamOutputMap.get(type)
          |                               ^
      146 |                 .filter((stream) => stream.getSource() === tributarySet.get('source'))
      147 |                 .map((stream) => tributarySet.set(type, stream)),
      148 |         ),

Expected Behavior

If an input has no output stream, it should simply return an empty array since there are no valid tributary maps.

Possible Solutions

We should account for cases where streamOutputMap.get(type) returns undefined. This could be as simple as replacing it with:

( streamOutputMap.get(type) || [] )

Related Issues

None.

slifty commented 4 years ago

Update: this only appears to happen if there is at least one output stream in the output map (otherwise there are no sources / seeds so it doesn't get to that line).

Still a bug, but the example code in this issue wasn't fully sufficient to reproduce.