Skip to content

The CLI might put the same error multiple times to the stderr #1761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
kittaakos opened this issue Jun 14, 2022 · 2 comments
Open
3 tasks done

The CLI might put the same error multiple times to the stderr #1761

kittaakos opened this issue Jun 14, 2022 · 2 comments
Assignees
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@kittaakos
Copy link
Contributor

Describe the problem

When compiling a broken sketch, the CLI might dump the error location multiple times to the std err. It is most likely related to how the sketch files are preprocessed and the prototype is created. (Of course, I am just guessing here 😊)

To reproduce

sketch_jun14c.ino:

void setup(){}
void loop() {
  byte = 2;
}
Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino: In function 'void loop()':
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:3:8: error: expected unqualified-id before '=' token
   byte = 2;
        ^

sketch_jun14c.ino:

void setup(){}
void 1loop() {
  byte = 2;
}
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:6: error: expected unqualified-id before numeric constant
 void 1loop() {
      ^~~~~

sketch_jun14c.ino:

void setup(){}
xvoid loop() {
  byte = 2;
}
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:1: error: 'xvoid' does not name a type; did you mean 'void'?
 xvoid loop() {
 ^~~~~
 void
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:1: error: 'xvoid' does not name a type; did you mean 'void'?
 xvoid loop() {
 ^~~~~
 void
Click to see full console output

a.kitta@Akoss-MacBook-Pro build % ~/Downloads/arduino-cli version                                                                         
arduino-cli  Version: nightly-20220614 Commit: 76fab32 Date: 2022-06-14T08:23:46Z
a.kitta@Akoss-MacBook-Pro build % cat ~/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino                                                 
void setup(){}
void loop() {
  byte = 2;
}%                                                                                                                                                              a.kitta@Akoss-MacBook-Pro build % ~/Downloads/arduino-cli compile -b arduino:mbed_nano:nanorp2040connect ~/Documents/Arduino/sketch_jun14c
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino: In function 'void loop()':
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:3:8: error: expected unqualified-id before '=' token
   byte = 2;
        ^



Used platform     Version Path                                                                      
arduino:mbed_nano 3.1.1   /Users/a.kitta/Library/Arduino15/packages/arduino/hardware/mbed_nano/3.1.1

Error during build: exit status 1
a.kitta@Akoss-MacBook-Pro build % cat ~/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino                                                 
void setup(){}
void 1loop() {
  byte = 2;
}%                                                                                                                                                              a.kitta@Akoss-MacBook-Pro build % ~/Downloads/arduino-cli compile -b arduino:mbed_nano:nanorp2040connect ~/Documents/Arduino/sketch_jun14c
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:6: error: expected unqualified-id before numeric constant
 void 1loop() {
      ^~~~~



Used platform     Version Path                                                                      
arduino:mbed_nano 3.1.1   /Users/a.kitta/Library/Arduino15/packages/arduino/hardware/mbed_nano/3.1.1

Error during build: exit status 1
a.kitta@Akoss-MacBook-Pro build % cat ~/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino                                                 
void setup(){}
xvoid loop() {
  byte = 2;
}%                                                                                                                                                              a.kitta@Akoss-MacBook-Pro build % ~/Downloads/arduino-cli compile -b arduino:mbed_nano:nanorp2040connect ~/Documents/Arduino/sketch_jun14c
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:1: error: 'xvoid' does not name a type; did you mean 'void'?
 xvoid loop() {
 ^~~~~
 void
/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:1: error: 'xvoid' does not name a type; did you mean 'void'?
 xvoid loop() {
 ^~~~~
 void



Used platform     Version Path                                                                      
arduino:mbed_nano 3.1.1   /Users/a.kitta/Library/Arduino15/packages/arduino/hardware/mbed_nano/3.1.1

Error during build: exit status 1

Expected behavior

I would expect to see the following error once:

/Users/a.kitta/Documents/Arduino/sketch_jun14c/sketch_jun14c.ino:2:1: error: 'xvoid' does not name a type; did you mean 'void'?
 xvoid loop() {
 ^~~~~
 void

Arduino CLI version

arduino-cli Version: nightly-20220614 Commit: 76fab32 Date: 2022-06-14T08:23:46Z

Operating system

macOS

Operating system version

12.3.1

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details
@kittaakos kittaakos added the type: imperfection Perceived defect in any part of project label Jun 14, 2022
@per1234
Copy link
Contributor

per1234 commented Jun 14, 2022

As you suspected, the issue can be understood more clearly by looking at the C++ code that is generated from the .ino file by the Arduino sketch preprocessor:

$ arduino-cli compile --fqbn arduino:avr:uno --preprocess C:/Users/per/Documents/Arduino/sketch_jun14c
#include <Arduino.h>
#line 1 "C:\\Users\\per\\Documents\\Arduino\\sketch_jun14c\\sketch_jun14c.ino"
#line 1 "C:\\Users\\per\\Documents\\Arduino\\sketch_jun14c\\sketch_jun14c.ino"
void setup();
#line 2 "C:\\Users\\per\\Documents\\Arduino\\sketch_jun14c\\sketch_jun14c.ino"
xvoid loop();
#line 1 "C:\\Users\\per\\Documents\\Arduino\\sketch_jun14c\\sketch_jun14c.ino"
void setup(){}
xvoid loop() {
  byte = 2;
}

#line directives are used to cause the messages generated from compiling that C++ file to match the line numbering of the source .ino file. This means there are actually two lines of code which are identified as line two:

The generated function prototype:

xvoid loop();

and the first line of the function definition:

xvoid loop() {

@per1234 per1234 added the topic: code Related to content of the project itself label Jun 14, 2022
@umbynos umbynos added the topic: build-process Related to the sketch build process label Feb 7, 2023
@cmaglie
Copy link
Member

cmaglie commented Apr 26, 2023

May be resolved if we create a parser for the generated errors: #1121

If we can parse the errors, we could easily add a de-duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

4 participants