Debugging an OpenGL application can be difficult. But OpenGL does provide ways to make debugging more reasonable.
OpenGL requires its functions to check their parameters for mistakes or inconsistencies, and emit errors when this occurs. Many other aspects of function calls are checked, to make sure that the current context state matches with what the system expects. If it does not, other errors are emitted.
These mechanisms only test malformed use of the API; there are many things that can go wrong which are not checked for. For these, there are a number of Debugging Tools available to help track down various issues.