|
| 1 | +# Copyright (C) 2015-2021 Regents of the University of California |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import urllib.parse as urlparse |
| 15 | + |
| 16 | + |
| 17 | +class InvalidImportExportUrlException(Exception): |
| 18 | + def __init__(self, url): |
| 19 | + """ |
| 20 | + :param urlparse.ParseResult url: |
| 21 | + """ |
| 22 | + super().__init__("The URL '%s' is invalid." % url.geturl()) |
| 23 | + |
| 24 | + |
| 25 | +class NoSuchJobException(Exception): |
| 26 | + """Indicates that the specified job does not exist.""" |
| 27 | + def __init__(self, jobStoreID): |
| 28 | + """ |
| 29 | + :param str jobStoreID: the jobStoreID that was mistakenly assumed to exist |
| 30 | + """ |
| 31 | + super().__init__("The job '%s' does not exist." % jobStoreID) |
| 32 | + |
| 33 | + |
| 34 | +class ConcurrentFileModificationException(Exception): |
| 35 | + """Indicates that the file was attempted to be modified by multiple processes at once.""" |
| 36 | + def __init__(self, jobStoreFileID): |
| 37 | + """ |
| 38 | + :param str jobStoreFileID: the ID of the file that was modified by multiple workers |
| 39 | + or processes concurrently |
| 40 | + """ |
| 41 | + super().__init__('Concurrent update to file %s detected.' % jobStoreFileID) |
| 42 | + |
| 43 | + |
| 44 | +class NoSuchFileException(Exception): |
| 45 | + """Indicates that the specified file does not exist.""" |
| 46 | + def __init__(self, jobStoreFileID, customName=None, *extra): |
| 47 | + """ |
| 48 | + :param str jobStoreFileID: the ID of the file that was mistakenly assumed to exist |
| 49 | + :param str customName: optionally, an alternate name for the nonexistent file |
| 50 | + :param list extra: optional extra information to add to the error message |
| 51 | + """ |
| 52 | + # Having the extra argument may help resolve the __init__() takes at |
| 53 | + # most three arguments error reported in |
| 54 | + # https://github.com/DataBiosphere/toil/issues/2589#issuecomment-481912211 |
| 55 | + if customName is None: |
| 56 | + message = "File '%s' does not exist." % jobStoreFileID |
| 57 | + else: |
| 58 | + message = "File '%s' (%s) does not exist." % (customName, jobStoreFileID) |
| 59 | + |
| 60 | + if extra: |
| 61 | + # Append extra data. |
| 62 | + message += " Extra info: " + " ".join((str(x) for x in extra)) |
| 63 | + |
| 64 | + super().__init__(message) |
| 65 | + |
| 66 | + |
| 67 | +class NoSuchJobStoreException(Exception): |
| 68 | + """Indicates that the specified job store does not exist.""" |
| 69 | + def __init__(self, locator): |
| 70 | + super().__init__("The job store '%s' does not exist, so there is nothing to restart." % locator) |
| 71 | + |
| 72 | + |
| 73 | +class JobStoreExistsException(Exception): |
| 74 | + """Indicates that the specified job store already exists.""" |
| 75 | + def __init__(self, locator): |
| 76 | + super().__init__( |
| 77 | + "The job store '%s' already exists. Use --restart to resume the workflow, or remove " |
| 78 | + "the job store with 'toil clean' to start the workflow from scratch." % locator) |
0 commit comments