Skip to content

The CLI provides different error messages when loading the main sketch file fails #1968

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 Nov 8, 2022 · 4 comments
Open
3 tasks done
Assignees
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@kittaakos
Copy link
Contributor

kittaakos commented Nov 8, 2022

Describe the problem

IDE2 must gracefully handle invalid sketch (folder) names and open them even if the CLI cannot load the sketch.

Since CLI can't provide error codes (#1762), IDE2 must parse the error message of the CLI and try to detect invalid sketch name problems. (See arduino/arduino-ide#1563)

Unfortunately, the CLI's error message quite often varies. As a consumer of the CLI, I would expect that the error message is the same if the problem is the same.

To reproduce

% tree                                                                        
.
├── Bar
│   └── xxx.ino
└── foo
    └── Foo.ino

2 directories, 2 files
% ~/dev/git/arduino-ide/arduino-ide-extension/build/arduino-cli version       
arduino-cli  Version: 0.28.0 Commit: 06fb1909 Date: 2022-10-20T08:42:20Z
% ~/dev/git/arduino-ide/arduino-ide-extension/build/arduino-cli compile -b arduino:avr:uno ./Bar 
Error opening sketch: main file missing from sketch: /Users/a.kitta/Desktop/invalid-sketches/Bar/Bar.ino
% ~/dev/git/arduino-ide/arduino-ide-extension/build/arduino-cli compile -b arduino:avr:uno ./foo 
Error opening sketch: no valid sketch found in /Users/a.kitta/Desktop/invalid-sketches/foo: missing /Users/a.kitta/Desktop/invalid-sketches/foo/foo.ino
Error opening sketch: main file missing from sketch: /Users/a.kitta/Desktop/invalid-sketches/Bar/Bar.ino
Error opening sketch: no valid sketch found in /Users/a.kitta/Desktop/invalid-sketches/foo: missing /Users/a.kitta/Desktop/invalid-sketches/foo/foo.ino

Expected behavior

No matter the final error message, it's the same if I want to load, compile, etc an invalid sketch. It should no matter if it's /foo/Foo.ino or /Bar/xxx.ino invalid, it's just invalid.

Arduino CLI version

Version: 0.28.0 Commit: 06fb190 Date: 2022-10-20T08:42:20Z

Operating system

macOS

Operating system version

12.5.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 Nov 8, 2022
@kittaakos
Copy link
Contributor Author

IDE2 must parse the error message of the CLI

Too bad, this won't work at all. IDE2 cannot rely on parsing the error message as it's different per locale. After setting the locale to it in the arduino-cli.yaml config file.

% ~/dev/git/arduino-ide/arduino-ide-extension/build/arduino-cli compile -b arduino:avr:uno ./Bar --config-file ~/.arduinoIDE/arduino-cli.yaml
Si è verificato un errore durante l'apertura dello sketch: il file principale manca dallo sketch: /Users/a.kitta/Desktop/invalid-sketches/Bar/Bar.ino
% ~/dev/git/arduino-ide/arduino-ide-extension/build/arduino-cli compile -b arduino:avr:uno ./foo --config-file ~/.arduinoIDE/arduino-cli.yaml
Si è verificato un errore durante l'apertura dello sketch: Non è stato trovato uno sketch valido in /Users/a.kitta/Desktop/invalid-sketches/foo: manca /Users/a.kitta/Desktop/invalid-sketches/foo/foo.ino

kittaakos pushed a commit to arduino/arduino-ide that referenced this issue Nov 8, 2022
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <[email protected]>
@per1234 per1234 added the topic: code Related to content of the project itself label Nov 9, 2022
kittaakos pushed a commit to arduino/arduino-ide that referenced this issue Nov 10, 2022
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <[email protected]>
kittaakos pushed a commit to arduino/arduino-ide that referenced this issue Nov 10, 2022
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <[email protected]>
kittaakos pushed a commit to arduino/arduino-ide that referenced this issue Nov 10, 2022
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <[email protected]>
kittaakos pushed a commit to arduino/arduino-ide that referenced this issue Nov 10, 2022
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <[email protected]>
kittaakos pushed a commit to arduino/arduino-ide that referenced this issue Nov 11, 2022
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <[email protected]>
@Bikappa Bikappa self-assigned this Jan 3, 2023
@Bikappa
Copy link
Contributor

Bikappa commented Jan 3, 2023

The two cases are logically different, at least from the code perspective. In the sketch initializer we look for a file named as the directory with the .ino extension as possible main file candidate.

  • with compile ./foo we find the file ./foo/Foo.ino (on MacOS and probably Windows as the locations are case insensitive there), which is then eventually considered invalid, when empty for example.
  • with compile ./Bar no file is found as main file candidate.

So the source problems seem to be the different and might deserve a different error message. @kittaakos wdyt?

@cmaglie
Copy link
Member

cmaglie commented Jan 3, 2023

which is then eventually considered invalid, when empty for example.

actually, it is explicitly checked for the correct file case

// checkSketchCasing returns an error if the casing of the sketch folder and the main file are different.
// Correct:
//
// MySketch/MySketch.ino
//
// Wrong:
//
// MySketch/mysketch.ino
// mysketch/MySketch.ino
//
// This is mostly necessary to avoid errors on Mac OS X.
// For more info see: https://github.com/arduino/arduino-cli/issues/1174
func (s *Sketch) checkSketchCasing() error {
files, err := s.FullPath.ReadDir()
if err != nil {
return errors.Errorf(tr("reading files: %v"), err)
}
files.FilterOutDirs()
candidateFileNames := []string{}
for ext := range globals.MainFileValidExtensions {
candidateFileNames = append(candidateFileNames, fmt.Sprintf("%s%s", s.Name, ext))
}
files.FilterPrefix(candidateFileNames...)
if files.Len() == 0 {
sketchFile := s.FullPath.Join(s.Name + globals.MainFileValidExtension)
return &InvalidSketchFolderNameError{
SketchFolder: s.FullPath,
SketchFile: sketchFile,
}
}
return nil
}

Maybe we can "normalize" the error message with "Invalid sketch found: <REASON>" so the check on the IDE side can be done against the prefix "Invalid sketch found:".

BTW as @kittaakos suggested this is fragile because the messages are localized, the real solution is to implement error codes #1762

@kittaakos
Copy link
Contributor Author

The two cases are logically different, at least from the code perspective.

Thank you for explaining this, but I opened the issue from the user's perspective.

So the source problems seem to be the different and might deserve a different error message.

I am not sure. As a user, I do know/mind how this is working internally. I want to load two sketches; both of them have an invalid name according to the spec, so I would expect the same error message. The detail/cause of the errors if any can differ.

Every sketch must contain a .ino file with a file name matching the sketch root folder name.

BTW as @kittaakos suggested this is fragile because the messages are localized, the real solution is to implement error codes #1762

I agree. Probably, no need to do anything with this issue once #1762 is resolved.

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

4 participants