{"record":{"id":"4430471ba7066011","repo":"arduino/Arduino","slug":"no-valid-code-files-found","errorCode":null,"errorMessage":"No valid code files found","messagePattern":"No valid code files found","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/Sketch.java","lineNumber":117,"sourceCode":"   * part of this sketch. Doesn't modify this SketchData instance, just\n   * returns a filtered and sorted list of File objects ready to be\n   * passed to the SketchFile constructor.\n   *\n   * @param showWarnings\n   *          When true, any invalid filenames will show a warning.\n   */\n  private List<SketchFile> listSketchFiles(boolean showWarnings) throws IOException {\n    Set<SketchFile> result = new TreeSet<>(CODE_DOCS_COMPARATOR);\n    for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) {\n      if (BaseNoGui.isSanitaryName(FileUtils.splitFilename(file).basename)) {\n        result.add(new SketchFile(this, file));\n      } else if (showWarnings) {\n        System.err.println(I18n.format(tr(\"File name {0} is invalid: ignored\"), file.getName()));\n      }\n    }\n\n    if (result.size() == 0)\n      throw new IOException(tr(\"No valid code files found\"));\n\n    return new ArrayList<>(result);\n  }\n\n  /**\n   * Create the data folder if it does not exist already. As a\n   * convenience, it also returns the data folder, since it's likely\n   * about to be used.\n   */\n  public File prepareDataFolder() {\n    File dataFolder = getDataFolder();\n    if (!dataFolder.exists()) {\n      dataFolder.mkdirs();\n    }\n    return dataFolder;\n  }\n\n  public void save() throws IOException {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/Sketch.java#L99-L135","documentation":"listSketchFiles scans the sketch folder for valid source files (.ino/.pde/.c/.cpp/.h etc.) and throws IOException when it finds none. It guarantees a Sketch is never built from an empty or all-invalid directory.","triggerScenarios":"Opening/saving a sketch whose folder contains zero files with a valid sketch extension — e.g. an empty folder, or a folder whose only files have invalid names that were skipped (with warnings when showWarnings is set).","commonSituations":"Pointing the IDE at an empty directory; a sketch moved from Windows where files got stripped; files with illegal characters in names silently ignored.","solutions":["Put at least one valid .ino/.pde source file (with a valid file name) in the sketch folder","Rename files to valid names (alphanumeric + underscore, starting with a letter)","Open the correct folder — the one containing the code, not its parent","Create a new sketch via File > New instead of opening the empty folder"],"exampleFix":"// before\nnew Sketch(new File(\"emptySketch\"), main);\n// after\nFile dir = new File(\"emptySketch\");\nFile[] entries = dir.listFiles((d, n) -> n.endsWith(\".ino\"));\nif (entries == null || entries.length == 0) {\n  System.err.println(\"Not a sketch folder: no .ino files\");\n  return;\n}\nnew Sketch(dir, main);","handlingStrategy":"validation","validationCode":"File[] sources = dir.listFiles((d, n) -> n.matches(\"[A-Za-z0-9_]+\\\\.(ino|pde|c|cpp|h)\") );\nif (sources == null || sources.length == 0) {\n  throw new IllegalArgumentException(\"No valid sketch sources in \" + dir);\n}","typeGuard":"static boolean isValidSketchFolder(File dir) {\n  File[] f = dir.listFiles((d, n) -> n.toLowerCase().endsWith(\".ino\") || n.toLowerCase().endsWith(\".pde\"));\n  return dir.isDirectory() && f != null && f.length > 0;\n}","tryCatchPattern":"try {\n  sketch.load();\n} catch (IOException e) {\n  if (\"No valid code files found\".equals(e.getMessage())) {\n    System.err.println(dir + \" has no valid sketch files\");\n  }\n}","preventionTips":["Check the folder contains at least one .ino/.pde before opening","Keep file names alphanumeric with underscores","Don't strip source files when moving sketches between machines","Enable showWarnings to see which files were skipped and why"],"tags":["sketch","empty","validation"],"backgroundTag":"empty-result-set","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}