Skip to content

Commit

Permalink
Merge pull request #87 from FRosner/issue/43
Browse files Browse the repository at this point in the history
#43 catch possible error when creating an instance
  • Loading branch information
FRosner authored Sep 25, 2016
2 parents a6f8024 + f7f79de commit 671fe2d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/de/frosner/broccoli/services/InstanceService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ class InstanceService @Inject()(templateService: TemplateService,
} else {
val potentialTemplate = templateService.template(templateId)
potentialTemplate.map { template =>
val newInstance = Instance(id, template, instanceCreation.parameters, InstanceStatus.Stopped, Map.empty)
instances = instances.updated(id, newInstance)
InstanceService.persistInstances(instances, new FileOutputStream(instancesFile))
Success(newInstance)
val maybeNewInstance = Try(Instance(id, template, instanceCreation.parameters, InstanceStatus.Stopped, Map.empty))
maybeNewInstance.map { newInstance =>
instances = instances.updated(id, newInstance)
InstanceService.persistInstances(instances, new FileOutputStream(instancesFile))
newInstance
}
}.getOrElse(Failure(newExceptionWithWarning(new IllegalArgumentException(s"Template $templateId does not exist."))))
}
}.getOrElse(Failure(newExceptionWithWarning(new IllegalArgumentException("No ID specified"))))
Expand Down

0 comments on commit 671fe2d

Please sign in to comment.