"use strict"; const unreachable = require("./")("unreachable-demo"); function someFunction(ducksEaten) { let mapping = { 1: "one", 2: "two", 3: "three" }; let mappedValue = mapping[ducksEaten]; if (mappedValue == null) { throw new Error(`Invalid value specified`); } else if (mappedValue === "one") { return "Only four little ducks came back"; } else if (mappedValue === "two") { return "Only three little ducks came back"; } else { // Oops, we forgot to add a case for "three"! Good thing we have a safety check here. unreachable(`Encountered unexpected mapped value '${mappedValue}'`); } } console.log(someFunction(1)); // Only four little ducks came back console.log(someFunction(2)); // Only three little ducks came back console.log(someFunction(3)); /* Error: Encountered unexpected mapped value 'three' -- this should never happen and it's a bug in 'unreachable-demo', please report it! at unreachable (/home/sven/projects/unreachable/index.js:5:9) at someFunction (/home/sven/projects/unreachable/example.js:21:3) at Object. (/home/sven/projects/unreachable/example.js:29:13) [ ... ] */