You can write this more idiomatically as
```
var localDirs = Option(System.getenv("YARN_LOCAL_DIRS"))
  .getOrElse(Option(System.getenv("LOCAL_DIRS"))
```
Then do your if test and return it. (Technically you can also do `.getOrElse(throw new Exception(...))` but that looks weirder.)