DEV Community

Discussion on: Dealing with Code Surprises: How Do You Handle Unexpected Results?

Collapse
 
gaurang847 profile image
Gaurang • Edited

I believe the single most important thing in these scenarios is logs.
If you have proper logs in place, you can

  • identify the input parameters

    e.g. What was the request body? Or function arguments?

  • trace the flow of execution
    e.g. What was the sequence of functions called for this request? Did these functions work as expected?

  • identify the area of fault
    e.g. If a sequence of functions are being called, which one seems to be giving a faulty output?

Sometimes, the logs may tell you exactly what went wrong.
Other times, it may at least give you some leads on what the problem might be.
Based on the logged input parameters, you might be able to reproduce the erroneous behavior on local or testing environment. And with further debugging and testing, you may identify the issue.