Skip to content

Validate that the stack is not Undefined #72

@ivarconr

Description

@ivarconr

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:

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) 
   })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions