From a97141682dffd8b5104cedd7155e1a87be2d5fb6 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Tue, 7 Nov 2023 14:57:02 +0000 Subject: [PATCH] Fixes #364. --- build.gradle | 2 +- docs/changelog.md | 4 ++++ src/main/java/com/structurizr/dsl/IncludeParser.java | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index eb32e27..820c88b 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ targetCompatibility = 17 description = 'Structurizr DSL' group = 'com.structurizr' -version = '1.33.0' +version = '1.33.1' test { useJUnitPlatform() diff --git a/docs/changelog.md b/docs/changelog.md index 4537df5..f6d08d5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 1.33.1 (unreleased) + +- Fixes https://github.com/structurizr/dsl/issues/364 (.DS_Store file causes exception during !include on Windows) + ## 1.33.0 (27th October 2023) - DSL identifiers (if present) will now be loaded when extending a JSON workspace (see https://github.com/structurizr/dsl/discussions/328). diff --git a/src/main/java/com/structurizr/dsl/IncludeParser.java b/src/main/java/com/structurizr/dsl/IncludeParser.java index 4386458..e3fcab8 100644 --- a/src/main/java/com/structurizr/dsl/IncludeParser.java +++ b/src/main/java/com/structurizr/dsl/IncludeParser.java @@ -40,14 +40,14 @@ void parse(IncludedDslContext context, Tokens tokens) { readFiles(context, path); } catch (IOException e) { - throw new RuntimeException(e.getMessage()); + throw new RuntimeException("Error including " + path.getAbsolutePath() + ": " + e.getMessage()); } } } } private void readFiles(IncludedDslContext context, File path) throws IOException { - if (path.isHidden()) { + if (path.isHidden() || path.getName().startsWith(".")) { // ignore return; } @@ -62,7 +62,11 @@ private void readFiles(IncludedDslContext context, File path) throws IOException } } } else { - context.addFile(path, Files.readAllLines(path.toPath(), StandardCharsets.UTF_8)); + try { + context.addFile(path, Files.readAllLines(path.toPath(), StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new RuntimeException("Error reading file at " + path.getAbsolutePath() + ": " + e.getMessage()); + } } }