OpenZeppelin / defender-serverless

Configure a Defender environment via code
20 stars 44 forks source link

Error messages for missing properties within sentinel.conditions could be more explicit #35

Closed peersky closed 1 year ago

peersky commented 2 years ago

Right now if one specifies a conditions for a sentinel, it is required to have both event and function arrays. From user perspective this requirement it is not really obvious: if I'm interested only in event I might assume function array is optional and write code which will not work.

i.e:

conditions:
          event:
            - signature: "Transfer(address,address,uint256)"
              expression: "from==${self:custom.config.cold-wallet.address}"

running deploy for such throws an error:

Cannot read properties of undefined (reading 'map')

While It can be fixed by adding function array to a conditions, it is not obvious from error message where the problem is.

        conditions:
          event:
            - signature: "Transfer(address,address,uint256)"
              expression: "from==${self:custom.config.cold-wallet.address}"
          function:
            - signature: ""

Proposed solution:

Return more explicit error

<sentinel_name>: conditions.function is missing

peersky commented 1 year ago

@shahnami https://github.com/OpenZeppelin/defender-serverless/blob/b44d7657d67958d7e1a506560d94d479be6d2aa7/src/types/index.ts#L124

One reading from typings ts file still might assume that both properties required