Skip to content

Incorrect compiler_err field contents from compile --format json when compiling .cpp file #1698

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

Closed
3 tasks done
NiklasKK opened this issue Mar 25, 2022 · 0 comments · Fixed by #2078
Closed
3 tasks done
Assignees
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@NiklasKK
Copy link

NiklasKK commented Mar 25, 2022

Describe the problem

The compiler_err field of the machine readable output formats are incorrect when compiling a .cpp file.

I use Arduino CLI for compiling a combination of standard .cpp/.c/.h files. Because an .ino file with the same name as the sketch is required I just put a blank .ino file inside the folder.

To reproduce

Structure of the test_sketch sketch:

test_sketch/
  ├── test_sketch.ino (empty file)
  ├── main.cpp (source code)

Content of main.cpp:

int main(){
    int i;
    while(1){
        ++i // < Missing semicolon to show wrong behaviour
    }
    return 0;
}

Current behavior

C:\Users\Niklas\Desktop\arduino_cli>arduino-cli compile test_sketch -b arduino:avr:uno --format json
{
  "compiler_out": "",
  "compiler_err": "\n",
  "builder_result": {
    "build_path": "C:\\Users\\Niklas\\AppData\\Local\\Temp\\arduino-sketch-305F5EF96041948188E749EEEDCF1C2F",
    "board_platform": {
      "id": "arduino:avr",
      "version": "1.8.4"
    },
    "build_platform": {
      "id": "arduino:avr",
      "version": "1.8.4"
    }
  },
  "success": false
}
Error during build: exit status 1

🐛 The value of the compiler_err field is \n instead of the error output from the compiler.

Expected behavior

The compiler_err field of the machine readable output contains the error output from the compiler.

Arduino CLI version

Original report

0.21.1

Last verified with

b3e8f8a

Operating system

Windows

Operating system version

11

Additional context

When running the command without the --format json flag the output is correct.

C:\Users\Niklas\Desktop\arduino_cli>arduino-cli compile test_sketch -b arduino:avr:uno
C:\Users\Niklas\Desktop\arduino_cli\test_sketch\main.cpp: In function 'int main()':
C:\Users\Niklas\Desktop\arduino_cli\test_sketch\main.cpp:5:5: error: expected ';' before '}' token
     }
     ^


Error during build: exit status 1

So I suspect it must have something to to with the conversion to JSON.

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
@per1234 per1234 self-assigned this Mar 25, 2022
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Mar 25, 2022
@per1234 per1234 assigned umbynos and unassigned per1234 Mar 25, 2022
@per1234 per1234 changed the title Unexpected behaviour of --format json option. Incorrect compiler_err field contents from compile --format json when compiling .cpp file Nov 4, 2022
@umbynos umbynos assigned cmaglie and unassigned umbynos Feb 7, 2023
cmaglie added a commit to cmaglie/arduino-cli that referenced this issue Feb 17, 2023
@cmaglie cmaglie linked a pull request Feb 20, 2023 that will close this issue
5 tasks
cmaglie added a commit to cmaglie/arduino-cli that referenced this issue Mar 10, 2023
cmaglie added a commit that referenced this issue Mar 10, 2023
* Added integration test for #1698

* Added helper functions to handle concurrent writes to ctx.Stdout/Stderr

* Do not alter ctx.Stderr/Stdout in ExecCommand

Some instances of ctx.Stdout may now contains nil since it's no more
altered during ExecCommand.

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

Successfully merging a pull request may close this issue.

4 participants