Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/scala/com/chrisomeara/pillar/Registry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object Registry {
files
.filterNot(file => file.isDirectory)
.filter(file => file.exists())
.filterNot(file => file.isHidden)
}

private def parseMigrationsInFiles(files: Seq[File]): Seq[Migration] = {
Expand All @@ -41,6 +42,9 @@ object Registry {
val stream = new FileInputStream(file)
try {
parser.parse(stream)
} catch {
case e: Exception =>
throw new RuntimeException(s"Error parsing migration file ${file}: ${e.getMessage}", e)
} finally {
stream.close()
}
Expand All @@ -51,7 +55,7 @@ object Registry {
if (!directory.isDirectory)
return List.empty

parseMigrationsInFiles(directory.listFiles())
parseMigrationsInFiles(filterExisting(directory.listFiles()))
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/pillar/migrations/faker/.a-dotfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
garbage
1 change: 1 addition & 0 deletions src/test/resources/pillar/migrations/garbage.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��?{u*�?
9 changes: 9 additions & 0 deletions src/test/scala/com/chrisomeara/pillar/RegistrySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class RegistrySpec extends FunSpec with BeforeAndAfter with ShouldMatchers with
registry.all.size should equal(0)
}
}

describe("with a file that contains garbage"){
it("throws an exception with a meaningful message") {
val exception = intercept[RuntimeException] {
Registry.fromFiles(Seq(new File("src/test/resources/pillar/migrations/garbage.cql")))
}
exception.getMessage should equal("Error parsing migration file src/test/resources/pillar/migrations/garbage.cql: Input length = 1")
}
}
}

describe("with a reporter parameter") {
Expand Down