Skip to content
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

#964 Prompt move when opening invalid sketch outside from IDE2 #1563

Merged
merged 1 commit into from
Oct 26, 2022
Merged

Conversation

kittaakos
Copy link
Contributor

@kittaakos kittaakos commented Oct 17, 2022

Motivation

The sketch folder name must match the name of the main sketch file. See the specs. This PR makes IDE2 more resilient by offering a sketch move to the user. This PR proposes the same behavior as IDE 1.x.

Change description

This PR consists of three changes:

  • handles the NOT_FOUND error received from the CLI and converts it into an "invalid sketch" error so that the frontend can handle it gracefully,
  • frontend can deal with files if the extension is .ino, previously only directories were supported in IDE2 as a workspace root from the URL#hash,
  • fixed the error in electron main when opening any (absolute and relative) paths on macOS and relative paths on Windows and Linux.

This PR also fixes #1484 by printing the version of the IDE2 to the console/logs.

Acceptance criteria:

Folder setup:

.
├── Arduino IDE.app # <-- this file is not contained in the attached ZIP :)
├── empty_workspace
├── my_workspace
│	      └── my_workspace.ino
├── other_folder
│             └── other_folder.ino
└── untitled folder2
    ├── fails_to_open
    ├── fails_to_open.ino
    └── sketch.ino
  • . is the cwd,
  • Move the test IDE2 build into the attached 964_test_folder.zip folder. (You do not have to, but all expectations and examples assume this setup. But all setups should equally work.)
  • After every use case, gracefully close the IDE2 with the File > Quit equivalent.
  1. Open empty_workspace:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./empty_workspace
    

    IDE2 opens and reloads with a fallback sketch. No notifications, no dialogs. A temp sketch is opened with the current date.

  2. Open the other_folder sketch folder with a relative path:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./other_folder
    

    IDE2 successfully opens the other_folder sketch.

  3. Open the other_folder.ino main sketch file with a relative path:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./other_folder/other_folder.ino
    

    IDE2 successfully opens the other_folder sketch.

  4. Open the my_workspace.ino main sketch file with an absolute path:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE /Users/a.kitta/Desktop/964_test_folder/my_workspace/my_workspace.ino
    

    IDE2 successfully opens the my_workspace sketch.

  5. Open my_workspace with a noncanonical path:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./other_folder/../my_workspace/
    

    IDE2 successfully opens the my_workspace sketch.

  6. Open IDE2 by clicking on my_workspace.ino icon on your OS. Or the context menu, select the appropriate IDE2 version to open with if you have multiple ones installed. Open other_folder.ino the same way. Close IDE2 with the File > Quit equivalent. Start the IDE2 from the terminal without any sketch paths or from the application icon:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE
    

    IDE2 successfully opens and restores both the my_workspace and the other_folder sketches.

  7. Open IDE2 by clicking on the untitled folder2/fails_to_open.ino icon. (See step 6. on how to open.)

    A fallback sketch opens. A modal dialog says that the fails_to_open.ino must be in a correctly named sketch folder. There is a notification message showing the original error message from the CLI.

    Click cancel. The fallback sketch is there, and IDE2 is fully functional.

    Screen Shot 2022-10-19 at 18 19 02
  8. Open untitled folder2/fails_to_open.ino from a terminal.

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./untitled\ folder2/fails_to_open.ino
    

    Expectations are the same as for step 8, but click on OK, and expect an error dialog; the folder already exists. Click on OK. The fallback sketch is there, and IDE2 is functional.

    Screen Shot 2022-10-19 at 18 53 09
  9. Open the untitled folder2/sketch.ino main sketch file from a terminal.

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./untitled\ folder2/sketch.ino
    

    Expectations are the same as for step 8. Click on OK. IDE2 reloads and moves the sketch to ./untitled folder2/sketch/sketch.ino. IDE2 is functional.

  10. Rename ./untitled\ folder2/sketch/sketch.ino to ./untitled\ folder2/sketch_old.ino

    mv ./untitled\ folder2/sketch/sketch.ino ./untitled\ folder2/sketch/sketch_old.ino
    

    Start IDE2 either from the application icon or without sketch folder params from a terminal:

    ./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE
    

    IDE2 prompts moving sketch_old.ino inside sketch_old/sketch_old.ino.

Screen Shot 2022-10-20 at 15 16 45


Handling multiple invalid sketch files:

When opening the IDE2 by pointing to the sketch folder which contains multiple invalid sketches, IDE2 picks the first invalid one. readdir(3) does not guarantee an ordering, so it is done by comparing the filenames.

touch ./untitled\ folder2/sketch/sketch_new.ino
% ls -al ./untitled\ folder2/sketch 
total 8
drwxr-xr-x  4 a.kitta  staff  128 Oct 19 18:37 .
drwxr-xr-x  6 a.kitta  staff  192 Oct 19 18:25 ..
-rw-r--r--  1 a.kitta  staff    0 Oct 19 18:37 sketch_new.ino
-rw-r--r--@ 1 a.kitta  staff   10 Oct 19 18:25 sketch_old.ino
./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./untitled\ folder2/sketch/

IDE2 will offer to move sketch_new.ino and not sketch_old.ino.


There is a notification message showing the original error message from the CLI.

This is open for discussion.

IDE 1.x shows something else besides the dialog:

Screen Shot 2022-10-19 at 18 57 12

IDE2 shows the error from the CLI:

Screen Shot 2022-10-19 at 18 59 07

  • IDE2 can omit to show anything,
  • Can tweak the error message,
  • CLI can provide a more user-friendly message.

When the IDE2 is started from a terminal, the path input can be a folder or a file:

  • if folder:
    • if exists and contains a valid main sketch file, the path will be used,
    • if exists but contains only invalid (main) sketch files, the path will be used,
    • if exists but does not contain any sketch files, the path will be used, but IDE2 will reload and will provide a fallback sketch,
    • if missing, IDE2 ignores the path argument and restores the previous sketches, if any. Otherwise, a fallback sketch will open.
  • if file:
    • if exists and is a .ino file, the parent folder will be used as the path to open the sketch,
    • if missing or not a .ino file, IDE2 ignores the path argument and restores the previous sketches, if any. Otherwise, a fallback sketch will open.

Other information

Closes #964
Closes #1484

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@kittaakos kittaakos added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Oct 17, 2022
@kittaakos kittaakos changed the title #964 Prompt move sketch when opening invalid sketch outside from IDE2 #964 Prompt move when opening invalid sketch outside from IDE2 Oct 17, 2022
@kittaakos kittaakos force-pushed the #964 branch 4 times, most recently from 09b2336 to 6562c15 Compare October 18, 2022 16:36
@kittaakos kittaakos marked this pull request as ready for review October 19, 2022 17:03
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dialog is not shown when opening sketch with mismatched file/folder names on Windows

To reproduce

Follow the instructions for (9) above.

🐛 The IDE starts up with a "fallback sketch" without showing a dialog to communicate the problem with the sketch to the user.

Expected behavior

The same behavior as when I attempt to open the file via File > Open:

image

Arduino IDE version

2.0.1-snapshot-c2f6cd6 (tester build for 37c30d5)

Operating system

Windows

Operating system version

10

Additional context

The IDE is working as expected under these conditions on Linux.


The problem occurs with both absolute and relative sketch paths.

The problem occurs with paths to both the sketch folder and sketch file.


I see this in the daemon logs (in this case I opened the sketch file via file association because the daemon logs output hangs the command line terminal):

2022-10-20 01:26:51 daemon INFO 4 CALLED: /cc.arduino.cli.commands.v1.ArduinoCoreService/LoadSketch

2022-10-20 01:26:51 daemon INFO 4 |  REQ:  {
4 |    "instance": {
4 |      "id": 1
4 |    },
4 |    "sketch_path": "c:\\ide 2\\rev\\untitled folder2"
4 |  }

2022-10-20 01:26:51 daemon INFO 4 |  ERROR:  rpc error: code = NotFound desc = Can't open sketch: main file missing from sketch: C:\ide 2\rev\untitled folder2\untitled folder2.ino

2022-10-20 01:26:51 daemon INFO 4 |  RESP: null
4 CALL END

5 CALLED: /cc.arduino.cli.commands.v1.ArduinoCoreService/LoadSketch
5 |  REQ:  {
5 |    "instance": {
5 |      "id": 1
5 |    },
5 |    "sketch_path": "c:\\ide 2\\rev"
5 |  }

2022-10-20 01:26:51 daemon INFO 5 |  ERROR:  rpc error: code = NotFound desc = Can't open sketch: main file missing from sketch: C:\ide 2\rev\rev.ino
5 |  RESP: null
5 CALL END

6 CALLED: /cc.arduino.cli.commands.v1.ArduinoCoreService/LoadSketch
6 |  REQ:  {
6 |    "instance": {
6 |      "id": 1
6 |    },
6 |    "sketch_path": "c:\\ide 2"
6 |  }

2022-10-20 01:26:51 daemon INFO 6 |  ERROR:  rpc error: code = NotFound desc = Can't open sketch: main file missing from sketch: C:\ide 2\ide 2.ino
6 |  RESP: null
6 CALL END

The first request matches what I see on the Linux machine, but the next two where the IDE attempts to load the parent paths as sketches is unique and strange.

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

Copy link
Contributor

@AlbyIanna AlbyIanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested all the cases on MacOS, and here are the results:


  1. expected: IDE2 opens and reloads with a fallback sketch. No notifications, no dialogs. A temp sketch is opened with the current date.
    actual: IDE2 opens the last open sketch (not a temp sektch)
  2. ❌ - I think there's just an error in the description of step 9, because in the premise you say to open fails_to_open.ino:

Open the untitled folder2/fails_to_open.ino main sketch file from a terminal.

./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./untitled\ folder2/fails_to_open.ino

and then you refer to sketch.ino:

Expectations are the same as for step 8. Click on OK. IDE2 reloads and moves the sketch to ./untitled folder2/sketch/sketch.ino. IDE2 is functional.

Probably you wanted to write:

  1. (corrected) Open the untitled folder2/sketch.ino main sketch file from a terminal.

./Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ./untitled\ folder2/sketch.ino

Expectations are the same as for step 8. Click on OK. IDE2 reloads and moves the sketch to ./untitled folder2/sketch/sketch.ino. IDE2 is functional.

Am I right? In that case,
9. (corrected) ✅
10. ✅

Arduino IDE version

12.0.1-snapshot-c2f6cd6 (tester build for 37c30d5)

Operating system

MacOS

Operating system version

13.3.1 (21E258)

@kittaakos
Copy link
Contributor Author

Am I right? In that case,

Yes, you're right. Thank you!

@kittaakos
Copy link
Contributor Author

Great review 👍


  • expected: IDE2 opens and reloads with a fallback sketch. No notifications, no dialogs. A temp sketch is opened with the current date.
    actual: IDE2 opens the last open sketch (not a temp sektch)

This has been fixed. ✅

Added additional notes about the expected behavior to the PR description: 👇

When the IDE2 is started from a terminal, the path input can be a folder or a file:

  • if folder:

    • if exists and contains a valid main sketch file, the path will be used,
    • if exists but contains only invalid (main) sketch files, the path will be used,
    • if exists but does not contain any sketch files, the path will be used, but IDE2 will reload and will provide a fallback sketch,
    • if missing, IDE2 ignores the path argument and restores the previous sketches, if any. Otherwise, a fallback sketch will open.
  • if file:

    • if exists and is a .ino file, the parent folder will be used as the path to open the sketch,
    • if missing or not a .ino file, IDE2 ignores the path argument and restores the previous sketches, if any. Otherwise, a fallback sketch will open.

9. ❌ - I think there's just an error in the description of step 9, because in the premise you say to open fails_to_open.ino:

Correct. The error was in the description. I have updated the expectation. ✅

I have downloaded the test build and went through the steps. All worked on my macOS installation. Please take another look, and let me know how it works. Thank you! 🙏

@AlbyIanna
Copy link
Contributor

AlbyIanna commented Oct 20, 2022

I did another run of tests with a new build, now 1. is working, but 7. fails.

Here are the new results

Open IDE2 by clicking on the untitled folder2/fails_to_open.ino icon. (See step 6. on how to open.)

A fallback sketch opens. A modal dialog says that the fails_to_open.ino must be in a correctly named sketch folder. There is a notification message showing the original error message from the CLI.

Result: IDE2 opens and reloads with a fallback sketch. No notifications, no dialogs. A temp sketch is opened with the current date.

Screen recording
Screen.Recording.2022-10-20.at.15.31.06.mov
8. ✅ 9. ✅ 10. ✅

Arduino IDE version

12.0.1-snapshot-de4e865 (tester build for 91c7cef)

Operating system

MacOS

Operating system version

13.3.1 (21E258)

@kittaakos
Copy link
Contributor Author

IDE2 shows the error from the CLI:

Screen Shot 2022-10-19 at 18 59 07
  • IDE2 can omit to show anything,
  • Can tweak the error message,
  • CLI can provide a more user-friendly message.

I have discussed this with Cristian, and the CLI can provide a fine-grained error message if the sketch (folder) name is invalid, etc. This will come later. For the time being, IDE2 will show the original error message from the CLI.

@kittaakos
Copy link
Contributor Author

but 7. fails.

I could not reproduce it. It works here with the build. Could you please double-check if you have picked the correct IDE2 version to open the invalid sketch?

964__step_7.mp4

@kittaakos
Copy link
Contributor Author

if you have picked the correct IDE2 version

Result: IDE2 opens and reloads with a fallback sketch. No notifications, no dialogs. A temp sketch is opened with the current date.

The attached video helped a lot. Yes, you opened the default IDE2, a nightly build by double-clicking on the .ino file. See the window title.

@AlbyIanna
Copy link
Contributor

The attached video helped a lot. Yes, you opened the default IDE2, a nightly build by double-clicking on the .ino file. See the window title.

oh, you're right! Sorry for that!
I tested it again with right build and it works correctly!

Copy link
Contributor

@AlbyIanna AlbyIanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything's working as expected for me.
Also code, looks good to me (I've just left two unimportant remarks)

Thank you Akos!

@kittaakos
Copy link
Contributor Author

@per1234, please take another look if you have time. Thank you!

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still experience the same problem as before:

Dialog is not shown when opening sketch with mismatched file/folder names on Windows

To reproduce

  1. Create a sketch which does not contain a .ino file matching the folder name:
    Foo/
    └── Bar.ino
    
  2. Open the Arduino IDE installation folder in a command line terminal.
  3. Pass the path to the sketch with the file/folder name mismatch as an argument to the Arduino IDE invocation:
    & ".\Arduino IDE" "C:\Users\per\Documents\Arduino\Foo\Bar.ino"
    
  4. Wait for the Arduino IDE to finish starting up.

🐛 The IDE starts up with a "fallback sketch" without showing a dialog to communicate the problem with the sketch to the user.

Expected behavior

The same behavior as when I attempt to open the file via File > Open:

image

Arduino IDE version

2.0.1-snapshot-6324f75 (tester build for fc4a668)

Operating system

Windows

Operating system version

10

Additional context

The IDE is working as expected under these conditions on Linux.


The problem occurs with both absolute and relative sketch paths.

The problem occurs with paths to both the sketch folder and sketch file.

Log IDE2 version on start.

Closes #964
Closes #1484

Co-authored-by: Alberto Iannaccone <a.iannaccone@arduino.cc>
Co-authored-by: Akos Kitta <a.kitta@arduino.cc>

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
@kittaakos
Copy link
Contributor Author

I could reproduce the defect on Windows and fix it. I have verified the case mentioned in #1563 (review), and it worked.

Please review. Thank you!

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working perfectly for me now. I verified it:

Thanks Akos!

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 this pull request may close these issues.

Dump IDE version to the log files Opening invalid sketch via file association/command line fails silently
3 participants