Skip to content

compile --preprocess panics if #included file not found #1947

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
per1234 opened this issue Oct 26, 2022 · 0 comments
Open
3 tasks done

compile --preprocess panics if #included file not found #1947

per1234 opened this issue Oct 26, 2022 · 0 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Oct 26, 2022

Describe the problem

If a sketch contains an #include directive for a file not present in any of the search paths, the arduino-cli compile --preprocess command panics.

To reproduce

$ arduino-cli version
arduino-cli.exe  Version: git-snapshot Commit: 13f22553 Date: 2022-10-26T06:09:43Z

$ mkdir /tmp/FooSketch

$ printf "#include <nonexistent.h>\nvoid setup() {}\nvoid loop() {}" > /tmp/FooSketch/FooSketch.ino

$ arduino-cli compile --fqbn arduino:avr:uno --preprocess /tmp/FooSketch/FooSketch.ino
C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:1:10: fatal error: nonexistent.h: No such file or directory
 #include <nonexistent.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0xc1f6f6]

goroutine 1 [running]:
github.com/arduino/arduino-cli/commands/compile.Compile({0x17432a0, 0xe5c9cd}, 0xc00014c160, {0x10cb900, 0xc000006018}, {0x10cb900, 0xc000006020}, 0x0, 0xc0)
        E:/electronics/git-nobackup/arduino-cli/commands/compile/compile.go:198 +0x1456
github.com/arduino/arduino-cli/cli/compile.runCompileCommand(0xc000359400, {0xc0002a47c0, 0x1, 0x4})
        E:/electronics/git-nobackup/arduino-cli/cli/compile/compile.go:235 +0xaaa
github.com/spf13/cobra.(*Command).execute(0xc000359400, {0xc0002a4780, 0x4, 0x4})
        C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0xc000275b80)
        C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
        C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
main.main()
        E:/electronics/git-nobackup/arduino-cli/main.go:31 +0x77

🐛 The stack trace from the panic does not provide any information of value to the user and may give them the impression the error was the result of a bug in Arduino CLI instead of with their sketch code.

Expected behavior

Arduino CLI only panics on unexpected (i.e., caused by a bug in the Arduino CLI codebase) failures. Any failure that can result from normal (even if incorrect) usage should be handled gracefully.

Arduino CLI version

13f2255

Operating system

Windows

Operating system version

10

Additional context

I bisected the introduction of the bug to 75b9760 / #1251

Before that, the output under these conditions was the more friendly:

$ arduino-cli compile --fqbn arduino:avr:uno --preprocess /tmp/FooSketch/FooSketch.ino
C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:1:10: fatal error: nonexistent.h: No such file or directory
 #include <nonexistent.h>
          ^~~~~~~~~~~~~~~
compilation terminated.

Error during build: exit status 1

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 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Oct 26, 2022
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

No branches or pull requests

1 participant