Skip to content

Commit

Permalink
Merge pull request #2821 from fan-tom/handle-empty-file-error
Browse files Browse the repository at this point in the history
Handle empty file error
  • Loading branch information
Shon Feder authored Jan 26, 2024
2 parents 003302f + f5da1a9 commit b8e7c83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .unreleased/bug-fixes/2800-error-on-empty-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When given an empty `.tla` file, report a clean user error instead of crashing
with an exception (#2821).
21 changes: 21 additions & 0 deletions test/tla/cli-integration-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ EXITCODE: ERROR (255)

This command parses a TLA+ specification with the SANY parser.

### parse blank file fails nicely

Create an empty file
```sh
$ touch blank.tla
```

Try to parse a blank file
```sh
$ apalache-mc parse blank.tla | sed 's/E@.*//'
...
Parsing error: No root module defined in file
...
EXITCODE: ERROR (255)
```

Cleanup
```sh
$ rm blank.tla
```

### parse Empty succeeds

```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class SanyImporter(sourceStore: SourceStore, annotationStore: AnnotationStore) e
ModuleTranslator(sourceStore, annotationStore).translate(node))
}

(specObj.getName, modmap)
specObj.getName match {
case null => throw new SanyImporterException("No root module defined in file")
case name => (name, modmap)
}
}

/**
Expand Down

0 comments on commit b8e7c83

Please sign in to comment.