diff options
| author | Jack Koenig | 2018-03-22 11:53:51 -0700 |
|---|---|---|
| committer | GitHub | 2018-03-22 11:53:51 -0700 |
| commit | ebb6847e9d01b424424ae11a0067448a4094e46d (patch) | |
| tree | fc87aa9d7b7d437914f6a4c9e20487c0973a1fc3 /src/main/scala/firrtl/Driver.scala | |
| parent | 6ea4ac666e4ce8dfaca1545660f372fccff610f5 (diff) | |
Better bad annotation file error reporting (#771)
* Propagate exceptions from JsonProtocol deserialization
* Add AnnotationFileNotFoundException for better error reporting
* Add AnnotationClassNotFoundException for better error reporting
* Better propagate JSON parsing errors
Also report the file if there is a error deserializing a JSON file
* Make exception for non-array JSON file more explicit
Diffstat (limited to 'src/main/scala/firrtl/Driver.scala')
| -rw-r--r-- | src/main/scala/firrtl/Driver.scala | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala index 3ff465e2..f9ba6141 100644 --- a/src/main/scala/firrtl/Driver.scala +++ b/src/main/scala/firrtl/Driver.scala @@ -116,23 +116,22 @@ object Driver { val loadedAnnos = annoFiles.flatMap { file => if (!file.exists) { - throw new FileNotFoundException(s"Annotation file $file not found!") + throw new AnnotationFileNotFoundException(file) } // Try new protocol first - JsonProtocol.deserializeTry(file).getOrElse { - val annos = Try { + JsonProtocol.deserializeTry(file).recoverWith { case jsonException => + // Try old protocol if new one fails + Try { val yaml = io.Source.fromFile(file).getLines().mkString("\n").parseYaml - yaml.convertTo[List[LegacyAnnotation]] + val result = yaml.convertTo[List[LegacyAnnotation]] + val msg = s"$file is a YAML file!\n" + + (" "*9) + "YAML Annotation files are deprecated! Use JSON" + Driver.dramaticWarning(msg) + result + }.orElse { // Propagate original JsonProtocol exception if YAML also fails + Failure(jsonException) } - annos match { - case Success(result) => - val msg = s"$file is a YAML file!\n" + - (" "*9) + "YAML Annotation files are deprecated! Use JSON" - Driver.dramaticWarning(msg) - result - case Failure(_) => throw new InvalidAnnotationFileException(file.toString) - } - } + }.get } val targetDirAnno = List(BlackBoxTargetDirAnno(optionsManager.targetDirName)) |
