Skip to content

Panic if sketch has build profile using local library dependency #905

@per1234

Description

@per1234

Describe the problem

Arduino Lint leverages some of the capabilities implemented in the Arduino CLI tool, via its github.com/arduino/arduino-cli Go module dependency.

Sketches may contain a sketch project file. Arduino CLI parses the content of the file when processing the sketch content.

The sketch project file may contain build profiles, which define the dependencies of the sketch.

Support for specifying dependencies on local libraries was recently added to Arduino CLI (arduino/arduino-cli#2930).

Use of the capabilities of Arduino CLI by other Go applications via the github.com/arduino/arduino-cli Go module was explicitly supported at the time Arduino Lint was written. However, it was later decided that maintaining a vast public API was simply not feasible. For this reason, almost the entire API of the Arduino CLI was made internal; only for use within the Arduino CLI application itself. This makes it impossible to update Arduino Lint's github.com/arduino/arduino-cli Go module dependency past the point when that change was made. So Arduino Lint is stuck using the outdated version arduino/arduino-cli@1f8d0f6c0dd3.

When the local library dependency feature of the build profiles system is used, the libraries sequence has a mapping type. Since prior to the introduction of the feature, the elements could only have a string type, older versions of Arduino CLI such as the one used by Arduino Lint do not have the ability to parse build profiles that contain local library dependencies.

🐛 Arduino Lint panics when linting a sketch that contains a build profile with a local library dependency.

To reproduce

  1. Click the following link to download a demonstration sketch:
    FooSketch.zip
  2. Wait for the download to finish.
  3. Extract the downloaded archive.
  4. Run Arduino Lint in the extracted folder.
    It is not necessary to pass any flags or arguments, just run the base arduino-lint command.

🐛 Arduino Lint panics:

$ /e/git/arduino/arduino-lint/arduino-lint

Linting sketch in E:\FooSketch
panic: profiles parsing err: yaml: unmarshal errors:
    line 5: cannot unmarshal !!map into string

goroutine 1 [running]:
github.com/arduino/arduino-cli/arduino/sketch.(*projectRaw).getProfiles(0xc00015c000)
  C:/Users/per/go/pkg/mod/github.com/arduino/[email protected]/arduino/sketch/profiles.go:84 +0x1fb
github.com/arduino/arduino-cli/arduino/sketch.LoadProjectFile(0xc00013e8c0?)
  C:/Users/per/go/pkg/mod/github.com/arduino/[email protected]/arduino/sketch/profiles.go:265 +0xb6
github.com/arduino/arduino-cli/arduino/sketch.New(0x2?)
  C:/Users/per/go/pkg/mod/github.com/arduino/[email protected]/arduino/sketch/sketch.go:90 +0x5a5
github.com/arduino/arduino-lint/internal/project/projectdata.InitializeForSketch(...)
  E:/git/arduino/arduino-lint/internal/project/projectdata/sketch.go:26
github.com/arduino/arduino-lint/internal/project/projectdata.Initialize({0xc000118070?, 0x1?, 0xc000239a90?})
  E:/git/arduino/arduino-lint/internal/project/projectdata/projectdata.go:37 +0x6f
github.com/arduino/arduino-lint/internal/rule.Runner({0xc000118070?, 0x0?, 0x0?})
  E:/git/arduino/arduino-lint/internal/rule/rule.go:37 +0xcb
github.com/arduino/arduino-lint/internal/command.ArduinoLint(0xc00011e100?, {0x0, 0x0, 0x0})
  E:/git/arduino/arduino-lint/internal/command/command.go:77 +0x3c5
github.com/spf13/cobra.(*Command).execute(0xc000193508, {0xc0000520c0, 0x0, 0x0})
  C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:1019 +0xa91
github.com/spf13/cobra.(*Command).ExecuteC(0xc000193508)
  C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x46f
github.com/spf13/cobra.(*Command).Execute(0x0?)
  C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:1071 +0x13
main.main()
  E:/git/arduino/arduino-lint/main.go:33 +0x18

Expected behavior

Linting passes for all sketches that contain a valid sketch project file.

In cases where there is a problem with a sketch, linting is always completed, with the rule violations clearly communicated in the standard manner. Panics should only ever occur when "impossible" conditions are encountered (i.e., a bug in Arduino Lint or its dependencies).

Arduino Lint version

9115109

Operating system

  • Linux
  • Windows

Operating system version

  • Ubuntu 24.04
  • Windows 11

Additional context

Originally reported at arduino-libraries/Arduino_UnifiedStorage#61 (comment).

Workaround

Remove the sketch project file, or comment out the problematic build profile content, before linting.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions