【发布时间】:2019-10-08 10:00:30
【问题描述】:
我正在生成如下错误消息:
throw `Do not recognize eventType '${eventType}', recognized events are ${recognizedEvents}.`;
问题是承认Events是一个对象,但它只是toString'ed...无论如何,所以我可以这样做:
throw `Do not recognize eventType '${eventType}', recognized events are ${util.inspect(recognizedEvents)}.`;
问题不仅在于它更冗长 - 有时我只是忘记调用 util.inspect()。如果直接传递对象,即使 TypeScript 也让我编译模板文字。这里有什么好的技术可以确保对象在日志中的合理深度得到检查?
【问题讨论】: