-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Hi,
We have sometimes had users report that a router layer does not have a stack on the handle'r, causing @unleash/unleash to crash at startup. It seems to happen when they run in environments with the dynatrace agent enabled. I have not been able to reproduce it, but still wonder if it would be wise to validate that the layer.handle.stack exists before iterating?
The problematic code:
Will crash when layer.handle.stack is undefined:
express-openapi/lib/generate-doc.js
Lines 78 to 82 in b56f6ee
| if (layer.name === 'router') { | |
| layer.handle.stack.forEach(l => { | |
| path = path || '' | |
| iterateStack(path + split(layer.regexp, layer.keys).join('/'), layer, l, cb) | |
| }) |
The proposed fix:
Here we added validation that the handle have a stack, as this code needs that to do its work. I think this would be safe to add, because the function would not be of any help if the stack does not exists, and would be similar to an empty array.
if (layer.name === 'router' && layer.handle.stack) {
layer.handle.stack.forEach(l => {
path = path || ''
iterateStack(path + split(layer.regexp, layer.keys).join('/'), layer, l, cb)
})