Indicates an error launching the server.
| 126 | # after construction in some cases. |
| 127 | @attr.s |
| 128 | class LaunchError(Exception): |
| 129 | """Indicates an error launching the server.""" |
| 130 | |
| 131 | log = attr.ib() # type: str |
| 132 | additional_msg = attr.ib(default=None) # type: Optional[str] |
| 133 | verbose = attr.ib(default=False) # type: bool |
| 134 | |
| 135 | def __str__(self): |
| 136 | # type: () -> str |
| 137 | lines = ["Error launching server."] |
| 138 | if self.additional_msg: |
| 139 | lines.append(self.additional_msg) |
| 140 | if self.verbose: |
| 141 | lines.append("Contents of the server log:") |
| 142 | with open(self.log) as fp: |
| 143 | lines.extend(fp.read().splitlines()) |
| 144 | else: |
| 145 | lines.append("See the log at {log} for more details.".format(log=self.log)) |
| 146 | return "\n".join(lines) |
| 147 | |
| 148 | |
| 149 | @attr.s(frozen=True) |