~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Patch Queue Manager
  • Date: 2011-11-28 11:49:43 UTC
  • mfrom: (6305.4.2 hpss-unknown-format)
  • Revision ID: pqm@pqm.ubuntu.com-20111128114943-exp17aodb5tydnkj
(jelmer) Print a sensible error message rather than a KeyError with a
 backtrace when a format is unknown. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
 
120
120
    def get_format_description(self):
121
121
        if self._network_name:
122
 
            real_format = controldir.network_format_registry.get(self._network_name)
123
 
            return 'Remote: ' + real_format.get_format_description()
 
122
            try:
 
123
                real_format = controldir.network_format_registry.get(
 
124
                        self._network_name)
 
125
            except KeyError:
 
126
                pass
 
127
            else:
 
128
                return 'Remote: ' + real_format.get_format_description()
124
129
        return 'bzr remote bzrdir'
125
130
 
126
131
    def get_format_string(self):
516
521
        if len(branch_info) != 2:
517
522
            raise errors.UnexpectedSmartServerResponse(response)
518
523
        branch_ref, branch_name = branch_info
519
 
        format = controldir.network_format_registry.get(control_name)
 
524
        try:
 
525
            format = controldir.network_format_registry.get(control_name)
 
526
        except KeyError:
 
527
            raise errors.UnknownFormatError(kind='control', format=control_name)
 
528
 
520
529
        if repo_name:
521
 
            format.repository_format = _mod_repository.network_format_registry.get(
522
 
                repo_name)
 
530
            try:
 
531
                format.repository_format = _mod_repository.network_format_registry.get(
 
532
                    repo_name)
 
533
            except KeyError:
 
534
                raise errors.UnknownFormatError(kind='repository',
 
535
                    format=repo_name)
523
536
        if branch_ref == 'ref':
524
537
            # XXX: we need possible_transports here to avoid reopening the
525
538
            # connection to the referenced location
528
541
            format.set_branch_format(branch_format)
529
542
        elif branch_ref == 'branch':
530
543
            if branch_name:
531
 
                format.set_branch_format(
532
 
                    branch.network_format_registry.get(branch_name))
 
544
                try:
 
545
                    branch_format = branch.network_format_registry.get(
 
546
                        branch_name)
 
547
                except KeyError:
 
548
                    raise errors.UnknownFormatError(kind='branch',
 
549
                        format=branch_name)
 
550
                format.set_branch_format(branch_format)
533
551
        else:
534
552
            raise errors.UnexpectedSmartServerResponse(response)
535
553
        return format
967
985
 
968
986
    def _ensure_real(self):
969
987
        if self._custom_format is None:
970
 
            self._custom_format = _mod_repository.network_format_registry.get(
971
 
                self._network_name)
 
988
            try:
 
989
                self._custom_format = _mod_repository.network_format_registry.get(
 
990
                    self._network_name)
 
991
            except KeyError:
 
992
                raise errors.UnknownFormatError(kind='repository',
 
993
                    format=self._network_name)
972
994
 
973
995
    @property
974
996
    def _fetch_order(self):
2610
2632
 
2611
2633
    def _ensure_real(self):
2612
2634
        if self._custom_format is None:
2613
 
            self._custom_format = branch.network_format_registry.get(
2614
 
                self._network_name)
 
2635
            try:
 
2636
                self._custom_format = branch.network_format_registry.get(
 
2637
                    self._network_name)
 
2638
            except KeyError:
 
2639
                raise errors.UnknownFormatError(kind='branch',
 
2640
                    format=self._network_name)
2615
2641
 
2616
2642
    def get_format_description(self):
2617
2643
        self._ensure_real()