Let's analyze the sentence:
The sentence is ruled by the predicate, which is a form of »geben« (to give). This verb has two mandatory complements:
- Who is giving?
- What is given?
Of those two complements, only one is performing the action (who?). The other complement is just the thing that is handed over (what?). That part, that performs the action, is the sentences subject, and it is always this subject, that stands in nominative case.
But if you say in English:
There is an error on the table.
Who is giving something? This question sounds weird, but since you use the verb geben (to give) in German, you have to ask this question. The answer is: Nobody. Nobody is giving anything in fact. Things just are, they are in fact not given. So you have nothing to place it into the subjects position.
And this exactly the situation where the syntactic expletive "es" comes in. When ever you have nothing you can use as Subject, you use "es". You do it English too:
Es regnet.
It rains.
Nobody is performing the action called "raining", but you need a subject. So you use an syntactic expletive.
The other mandatory completion of the verb "geben" is that part, that tells us what is given ("an error"). This has to be set in accusative case, so it has to be "einen Fehler" in German. It is the verb geben that forces its mandatory object to be in accusative case.
The prepositional object is an optional object. A sentence without it would be correct too.
Es gibt einen Fehler.
In this case it contains the information where an error exists:
Es gibt einen Fehler auf dem Tisch.