Skip to content

Improve or remove Keyboard/Mouse compilation error interpretations #1126

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 Jun 29, 2022 · 0 comments
Open
3 tasks done

Improve or remove Keyboard/Mouse compilation error interpretations #1126

per1234 opened this issue Jun 29, 2022 · 0 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@per1234
Copy link
Contributor

per1234 commented Jun 29, 2022

Describe the request

Evaluate the often irrelevant supplemental interpretations the Arduino IDE provides on Keyboard and Mouse library-related compilation errors.

  • Can false interpretations be reduced?
  • Can the interpretation message be adjusted to avoid confusion in the event of false positives?
  • Should the interpretations be removed altogether?

Describe the current behavior

The Arduino IDE attempts to provide some additional guidance to users in response to some specific compilation error messages:

/**
* Converts cryptic and legacy error messages to nice ones. Taken from the Java IDE.
*/
function remapErrorMessages(result: ParseResult): ParseResult {
const knownError = KnownErrors[result.error];
if (!knownError) {
return result;
}
const { message, error } = knownError;
return {
...result,
...(message && { message }),
...(error && { error }),
};
}
// Based on the Java IDE: https://github.com/arduino/Arduino/blob/43b0818f7fa8073301db1b80ac832b7b7596b828/arduino-core/src/cc/arduino/Compiler.java#L528-L578
const KnownErrors: Record<string, { error: string; message?: string }> = {
"'Mouse' was not declared in this scope": {
error: nls.localize(
'arduino/cli-error-parser/mouseError',
"'Mouse' not found. Does your sketch include the line '#include <Mouse.h>'?"
),
},
"'Keyboard' was not declared in this scope": {
error: nls.localize(
'arduino/cli-error-parser/keyboardError',
"'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?"
),
},
};

This is accomplished by matching a subset of the error message produced by the compilation toolchain and then printing an additional message in a notification and to the "Output" panel. That message is intended to make the cause and resolution for the error easier for less advanced users to understand.

Two such interpretations were put in place at the time of a breaking change 7 years ago resulting from moving the popular keyboard and mouse emulation APIs out of the core to standalone libraries: arduino/Arduino#3304

Prior to the change, the APIs could be used without adding an extra #include directive to the sketch:

void setup() {
  Keyboard.begin();
  Keyboard.print("hello");
}
void loop() {}

After the change, it was necessary to add an #include directive for the appropriate header file:

#include <Keyboard.h>
void setup() {
  Keyboard.begin();
  Keyboard.print("hello");
}
void loop() {}

Attempting to compile the previously valid code results in an error:

C:\Users\per\AppData\Local\Temp\.arduinoIDE-unsaved2022528-3144-18az9y0.lofa\sketch_jun28a\sketch_jun28a.ino: In function 'void setup()':
C:\Users\per\AppData\Local\Temp\.arduinoIDE-unsaved2022528-3144-18az9y0.lofa\sketch_jun28a\sketch_jun28a.ino:2:3: error: 'Keyboard' was not declared in this scope
   Keyboard.begin();
   ^~~~~~~~

exit status 1

These supplemental interpretations are also displayed by the Arduino IDE:

'Mouse' not found. Does your sketch include the line '#include <Mouse.h>'?

'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

Arduino and the Arduino community have done a good job of adapting to the change and it is now very rare to find any legacy code without these #include directives. There is always the chance a user will forget to add an #include directive in a sketch they write from scratch, but that is just as likely to occur with any arbitrary header file, so does not justify giving these two special treatment.

Meanwhile, another mistake related to keyboard and mouse emulation code is just as prevalent as ever: attempting to use it with a board which does not have native USB support (e.g., Uno, Mega). Unfortunately, doing this produces the same compilation error as omitting the #include directive, which also triggers the interpretations. In this case the interpretation message is completely irrelevant because the user already has that #include directive in their sketch and the error is caused by something completely different.

🙁 The interpretation message increases confusion in the cases where it is irrelevant. The cases where it is relevant are increasingly rare as time goes on.

Arduino IDE version

2.0.0-rc8-snapshot-34ef25c

Operating system

Windows

Operating system version

10

Additional context

Related: #1113

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the latest nightly build
  • My request contains all necessary details
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jun 29, 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: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

2 participants