Print a useful error message for the current exception. This is supposed to catch all exceptions, and should never raise any exceptions itself.
(status_name=None, e=None)
| 60 | |
| 61 | |
| 62 | def handle_cli_error(status_name=None, e=None): |
| 63 | ''' |
| 64 | Print a useful error message for the current exception. |
| 65 | |
| 66 | This is supposed to catch all exceptions, and should never raise any |
| 67 | exceptions itself. |
| 68 | ''' |
| 69 | |
| 70 | try: |
| 71 | if e is not None: |
| 72 | raise e |
| 73 | else: |
| 74 | raise |
| 75 | except exceptions.UserError as e: |
| 76 | cli_logger.critical(e) |
| 77 | except StorageEmpty as e: |
| 78 | cli_logger.error( |
| 79 | '{status_name}: Storage "{name}" was completely emptied. If you ' |
| 80 | 'want to delete ALL entries on BOTH sides, then use ' |
| 81 | '`vdirsyncer sync --force-delete {status_name}`. ' |
| 82 | 'Otherwise delete the files for {status_name} in your status ' |
| 83 | 'directory.'.format( |
| 84 | name=e.empty_storage.instance_name, |
| 85 | status_name=status_name |
| 86 | ) |
| 87 | ) |
| 88 | except PartialSync as e: |
| 89 | cli_logger.error( |
| 90 | '{status_name}: Attempted change on {storage}, which is read-only' |
| 91 | '. Set `partial_sync` in your pair section to `ignore` to ignore ' |
| 92 | 'those changes, or `revert` to revert them on the other side.' |
| 93 | .format(status_name=status_name, storage=e.storage) |
| 94 | ) |
| 95 | except SyncConflict as e: |
| 96 | cli_logger.error( |
| 97 | '{status_name}: One item changed on both sides. Resolve this ' |
| 98 | 'conflict manually, or by setting the `conflict_resolution` ' |
| 99 | 'parameter in your config file.\n' |
| 100 | 'See also {docs}/config.html#pair-section\n' |
| 101 | 'Item ID: {e.ident}\n' |
| 102 | 'Item href on side A: {e.href_a}\n' |
| 103 | 'Item href on side B: {e.href_b}\n' |
| 104 | .format(status_name=status_name, e=e, docs=DOCS_HOME) |
| 105 | ) |
| 106 | except IdentConflict as e: |
| 107 | cli_logger.error( |
| 108 | '{status_name}: Storage "{storage.instance_name}" contains ' |
| 109 | 'multiple items with the same UID or even content. Vdirsyncer ' |
| 110 | 'will now abort the synchronization of this collection, because ' |
| 111 | 'the fix for this is not clear; It could be the result of a badly ' |
| 112 | 'behaving server. You can try running:\n\n' |
| 113 | ' vdirsyncer repair {storage.instance_name}\n\n' |
| 114 | 'But make sure to have a backup of your data in some form. The ' |
| 115 | 'offending hrefs are:\n\n{href_list}\n' |
| 116 | .format(status_name=status_name, |
| 117 | storage=e.storage, |
| 118 | href_list='\n'.join(map(repr, e.hrefs))) |
| 119 | ) |