Arduino build error

error: expected '}' at end of input

The file ended while a function or block was still open. There are more { than } in the sketch.

  • Build error
  • 2 common causes
  • Seen 2,761 times in failed builds on Mokxi in the 30 days to November 16, 2026.
The message

What the Arduino IDE prints

Output window
sketch.ino: In function 'void loop()':
sketch.ino:9:1: error: expected '}' at end of input
exit status 1

The reported line is the last one. The missing brace is somewhere above, in the block that was never closed.

Mokxi's compiler, clang, words it as expected '}', with a note pointing at the brace that was never closed.

Causes

The 2 usual causes with the fix

1A block was opened and not closed

Count the braces of the block you edited last. Each { needs its own }. When the next function then looks like it starts inside the open block, Mokxi says so.

Broken
void setup() {
  Serial.begin(9600);
  if (true) {
    Serial.println("open");
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  if (true) {
    Serial.println("open");
  }
}

void loop() {
}

Mokxi’s build tab says: A function starts inside another one.

Try this fix in Mokxi

2A brace was deleted while editing

Cutting and pasting lines can take a closing brace with them. The last function is the one reported, though it is not the broken one.

Broken
void setup() {
  Serial.begin(9600);
  Serial.println("start");
}

void loop() {
  delay(1000);
Fixed
void setup() {
  Serial.begin(9600);
  Serial.println("start");
}

void loop() {
  delay(1000);
}

Mokxi’s build tab says: The { on line 6 is never closed.

Try this fix in Mokxi

FAQ

Questions and answers

What does "expected '}' at end of input" mean?

The sketch ended before every opened brace was closed. A closing brace is missing.

How do I find which brace is missing?

Press Auto Format. The code after the missing brace is indented one level too far, which shows where the block should have closed.

Can a missing brace in a library cause this?

Rarely. The error is almost always in your own sketch, and the file name in the message says which tab.