synechron-code / probr-pack-storage

Apache License 2.0
0 stars 3 forks source link

[BUG] - Update audit logic in all scenarios for all probes #7

Closed lluuiissoo closed 3 years ago

lluuiissoo commented 3 years ago

Describe the bug If an unhandled error occurs within a probe scenario, then the step will pass since error is not caught. Example: invalid memory address or nil pointer dereference

To Reproduce Steps to reproduce the behavior:

  1. Go to any probe
  2. Add logic to access a pointer that have not been initialized
  3. Run the test
  4. In audit log, see the step result is Passed, however Function is panicmem image

Expected behavior Any unhandled error within a probe should be caught and step should fail. The logic for deferred audit shall be update in all probe scenarios as follows:

        // Standard auditing logic to ensures panics are also audited
    stepTrace, payload, err := utils.AuditPlaceholders()
    defer func() {
        // Catching any errors from panic
        if panicErr := recover(); panicErr != nil {
            err = utils.ReformatError("Unexpected error occured: ", panicErr)
        }
        scenario.audit.AuditScenarioStep(scenario.currentStep, stepTrace.String(), payload, err)
    }()

Screenshots image

Additional context https://www.digitalocean.com/community/tutorials/handling-panics-in-go