[spec] Main sketch filename length

Hi there,

Can somebody help with the specs? It's unclear to me.

From the Sketch folders and files specs:

root folder name and code file

The maximum length is 63 characters.

Is this a valid main sketch filename?

012345678901234567890123456789012345678901234567890123456789123.ino

Thank you!

Welcome to the forum

What happened when you tried it ?

Since the name can include dots, I would hazard a guess that the 4 characters comprising the .ino extension are included in the maximum length count. The example would therefore have 67 characters....

Quite why anyone would want a filename that long... well I guess that's another matter.

Hi :wave:

I was not looking at how one of your software implements the specs, but what it means. It was not clear. But I did the testing.

Create a sketch with the following (64 chars length + .ino !invalid) sketch folder name:

0123456789012345678901234567890123456789012345678901234567891234.ino

It should be invalid as it consists of 68 chars with the extension. But it works. I could verify the sketch.

Try to open the previously created sketch with the other app. Get a message:

The spec allows dots:

followed by basic letters, numbers, underscores (_ ), dots (. ) and dashes (- ).

I manually removed the last 4 char and the .ino extension from both the sketch folder and file names. Now the length is 63. This:

012345678901234567890123456789012345678901234567890123456789123

Now, I can open the file.

Let's save the sketch with this content:

void setup() {
 // I worked on this code 8+ hours.
}
void loop() {}

Create a new sketch with this content:

void setup() {
  // junk
}
void loop() {}

Save the sketch folder and save it with the invalid filename (with the trailing 4 but no .ino):

0123456789012345678901234567890123456789012345678901234567891234

The app logs this:

The sketch name had to be modified.
Sketch names must start with a letter or number, followed by letters,
numbers, dashes, dots and underscores. Maximum length is 63 characters.

I go to the filesystem, and the intelligent name correction has silently overridden the previous content:

% cat 012345678901234567890123456789012345678901234567890123456789123.ino 
void setup() {
  // junk
}
void loop() {}

I did not try your web app, but presumably, every software works differently. What's the correct behavior? Thank you!

1 Like

You found a limit and a bug.
Which Arduino IDE file and which operating system do you use ?

I can not find that Java or the compiler has a limit of 63 characters, so I assume that it is the Arduino software.

[UPDATE]
Tested with Arduino IDE 1.8.19 (downloaded as the tar.gz 64-bit) running in linux.
When I try long filenames, then I get all kind of messages, as popup window, in the compiler output field, in the system error about Java (I run it from a terminal).
In most cases I have to exit the Arduino IDE and fix the filenames or remove the files.
It is probably not fully tested, this method to lose the content was overlooked.

There is no guarantee that the tooling will enforce the specification. There is also no guarantee that the tooling will continue to support non-compliant projects.

In some cases, the tooling is intentionally lenient, most often when it comes to libraries and boards platforms which are not something the average user is able to fix easily. When it comes to sketches it is more reasonable to be strict about enforcing the specification since the user is more likely to be the creator of the sketch. I suspect it is simply that the developers didn't think to add any check for the length. You will find Arduino IDE 2.x also allows non-compliant characters in the sketch name.

The Arduino IDE 1.x developers had more of a tendency to enforce or encourage compliance via the IDE. The new approach tends to be to use a dedicated linter tool for enforcing specification compliance and encouraging best practices:

https://arduino.github.io/arduino-lint/latest/

(note rule SS003)

The sketch folder name must not exceed 63 characters.

The names (not including extension) of sketch files must not exceed 63 characters.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.