Changeset - 2fa9f497faac
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2020-03-17 17:15:59
mads@kiilerich.com
repos: separate repo creation from form validation

The broad catching of Exception in the repo creation controller is conceptually
bad. It also caused misleading "Error creating repository None" when form
validation failed with anything but formencode.Invalid . For now, just
constrain the broad exception handling to only cover repo creation. It is a bug
if form validation fails in unexpected ways, and we want it reported as a crash
that we can fix.
1 file changed with 5 insertions and 6 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/repos.py
Show inline comments
 
@@ -112,17 +112,11 @@ class ReposController(BaseRepoController
 
    @NotAnonymous()
 
    def create(self):
 
        self.__load_defaults()
 
        form_result = {}
 
        try:
 
            # CanWriteGroup validators checks permissions of this POST
 
            form_result = RepoForm(repo_groups=c.repo_groups,
 
                                   landing_revs=c.landing_revs_choices)() \
 
                            .to_python(dict(request.POST))
 

	
 
            # create is done sometimes async on celery, db transaction
 
            # management is handled there.
 
            task = RepoModel().create(form_result, request.authuser.user_id)
 
            task_id = task.task_id
 
        except formencode.Invalid as errors:
 
            log.info(errors)
 
            return htmlfill.render(
 
@@ -133,6 +127,11 @@ class ReposController(BaseRepoController
 
                force_defaults=False,
 
                encoding="UTF-8")
 

	
 
        try:
 
            # create is done sometimes async on celery, db transaction
 
            # management is handled there.
 
            task = RepoModel().create(form_result, request.authuser.user_id)
 
            task_id = task.task_id
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            msg = (_('Error creating repository %s')
0 comments (0 inline, 0 general)