Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages for opening repos. #698

Merged
merged 2 commits into from
Apr 5, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/pygit2.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,35 @@ PyDoc_STRVAR(init_file_backend__doc__,
PyObject *
init_file_backend(PyObject *self, PyObject *args)
{
const char* path;
const char* path = NULL;
int err = GIT_OK;
git_repository *repository = NULL;
if (!PyArg_ParseTuple(args, "s", &path)) {
return NULL;
};
}

err = git_repository_open(&repository, path);

if (err < 0) {
Error_set_str(err, path);
err = -1;
goto cleanup;
}

return PyCapsule_New(repository, "backend", NULL);

cleanup:
if (repository)
if (repository) {
git_repository_free(repository);

PyErr_Format(PyExc_Exception,
"Git error %d during construction of git repo", err);
}

if (err == GIT_ENOTFOUND) {
PyErr_Format(PyExc_Exception,
"Repository not found at %s", path);
} else {
PyErr_Format(PyExc_Exception,
"Git error %d while opening repo at %s", err, path);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. While you are at it, maybe change style to use 4 spaces indentation. Also, Exception is too generic, we should use a more specific exception; though choosing a good one is not easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a GitError exception we can use?
And, do we have a style guide? I saw #238, but since it's open sinse 2013 I didn't really know what to make of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just realized we have different indentation inside the same function... Fixing that now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it simple: PEP 7 for C, PEP 8 for Python.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed a commit to raise GitError for GIT_ENOTFOUND (and to not change the error set by Error_set_str for the other cases, to avoid hiding information).

return NULL;
}

Expand Down