You can find out (part of) the context you are in by:
cont = bpy.context.area.type
print(str(cont))
This in itself will help you determine where you are (contextually speaking).
Determining where you need to be is another story. Each operation that you
do in Blender requires that you be in the correct context. The way I think
of context is, what window (context) does the operation occur in when you
do the action by clicking with the mouse? You also may need to refer to the API
or other info, but one thing I found to help is knowing what contexts exist!
And easy way to find that out is:
bpy.context.area.type = '?'
This throws a useful error:
TypeError: bpy_struct: item.attr = val: enum "?" not found in ('VIEW_3D', 'TIMELINE', 'GRAPH_EDITOR', 'DOPESHEET_EDITOR', 'NLA_EDITOR', 'IMAGE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'TEXT_EDITOR', 'NODE_EDITOR', 'LOGIC_EDITOR', 'PROPERTIES', 'OUTLINER', 'USER)
Well, there are your context types . . .
I don't know if that has successfully answered your question, because I do not write
plugins, yet, but it might has something that helps get you past the current issue in it.