diff options
| -rw-r--r-- | error.py | 7 | ||||
| -rwxr-xr-x | main.py | 27 | ||||
| -rw-r--r-- | project.py | 4 |
3 files changed, 25 insertions, 13 deletions
| @@ -24,6 +24,13 @@ class ManifestInvalidRevisionError(Exception): | |||
| 24 | class NoManifestException(Exception): | 24 | class NoManifestException(Exception): |
| 25 | """The required manifest does not exist. | 25 | """The required manifest does not exist. |
| 26 | """ | 26 | """ |
| 27 | def __init__(self, path, reason): | ||
| 28 | super(NoManifestException, self).__init__() | ||
| 29 | self.path = path | ||
| 30 | self.reason = reason | ||
| 31 | |||
| 32 | def __str__(self): | ||
| 33 | return self.reason | ||
| 27 | 34 | ||
| 28 | class EditorError(Exception): | 35 | class EditorError(Exception): |
| 29 | """Unspecified error from the user's text editor. | 36 | """Unspecified error from the user's text editor. |
| @@ -129,8 +129,15 @@ class _Repo(object): | |||
| 129 | file=sys.stderr) | 129 | file=sys.stderr) |
| 130 | return 1 | 130 | return 1 |
| 131 | 131 | ||
| 132 | copts, cargs = cmd.OptionParser.parse_args(argv) | 132 | try: |
| 133 | copts = cmd.ReadEnvironmentOptions(copts) | 133 | copts, cargs = cmd.OptionParser.parse_args(argv) |
| 134 | copts = cmd.ReadEnvironmentOptions(copts) | ||
| 135 | except NoManifestException as e: | ||
| 136 | print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)), | ||
| 137 | file=sys.stderr) | ||
| 138 | print('error: manifest missing or unreadable -- please run init', | ||
| 139 | file=sys.stderr) | ||
| 140 | return 1 | ||
| 134 | 141 | ||
| 135 | if not gopts.no_pager and not isinstance(cmd, InteractiveCommand): | 142 | if not gopts.no_pager and not isinstance(cmd, InteractiveCommand): |
| 136 | config = cmd.manifest.globalConfig | 143 | config = cmd.manifest.globalConfig |
| @@ -146,15 +153,13 @@ class _Repo(object): | |||
| 146 | start = time.time() | 153 | start = time.time() |
| 147 | try: | 154 | try: |
| 148 | result = cmd.Execute(copts, cargs) | 155 | result = cmd.Execute(copts, cargs) |
| 149 | except DownloadError as e: | 156 | except (DownloadError, ManifestInvalidRevisionError, |
| 150 | print('error: %s' % str(e), file=sys.stderr) | 157 | NoManifestException) as e: |
| 151 | result = 1 | 158 | print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)), |
| 152 | except ManifestInvalidRevisionError as e: | 159 | file=sys.stderr) |
| 153 | print('error: %s' % str(e), file=sys.stderr) | 160 | if isinstance(e, NoManifestException): |
| 154 | result = 1 | 161 | print('error: manifest missing or unreadable -- please run init', |
| 155 | except NoManifestException as e: | 162 | file=sys.stderr) |
| 156 | print('error: manifest required for this command -- please run init', | ||
| 157 | file=sys.stderr) | ||
| 158 | result = 1 | 163 | result = 1 |
| 159 | except NoSuchProjectError as e: | 164 | except NoSuchProjectError as e: |
| 160 | if e.name: | 165 | if e.name: |
| @@ -2327,8 +2327,8 @@ class Project(object): | |||
| 2327 | path = os.path.join(self._project.worktree, '.git', HEAD) | 2327 | path = os.path.join(self._project.worktree, '.git', HEAD) |
| 2328 | try: | 2328 | try: |
| 2329 | fd = open(path, 'rb') | 2329 | fd = open(path, 'rb') |
| 2330 | except IOError: | 2330 | except IOError as e: |
| 2331 | raise NoManifestException(path) | 2331 | raise NoManifestException(path, str(e)) |
| 2332 | try: | 2332 | try: |
| 2333 | line = fd.read() | 2333 | line = fd.read() |
| 2334 | finally: | 2334 | finally: |
