jelmer / xandikos

A CalDAV/CardDAV server backed by Git
https://www.xandikos.org/
GNU General Public License v3.0
410 stars 42 forks source link

print proper error when unable to determine git identity #254

Closed d5ve closed 1 year ago

d5ve commented 1 year ago

I'm getting a 500 error when trying to create a new event from the MacOS calendar app.

xandikos (ghcr.io/jelmer/xandikos:latest) is running in a docker container behind a caddy2 proxy.

The MacOC calendar app can sucessfully login and read calendar events, but is failing to save new ones.

The python error is below, but I don't really know what to look for here.

$ docker logs xandikos
<snip>
172.19.0.2 [04/Sep/2023:06:37:56 +0000] "PROPFIND /user/calendars/ HTTP/1.1" 207 11124 "-" "macOS/13.4.1 (22F82) dataaccessd/1.0"
Error handling request
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/lib/python3/dist-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/lib/python3/dist-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/lib/python3/dist-packages/aiohttp_openmetrics/__init__.py", line 62, in metrics_middleware
    response = await handler(request)
  File "/code/xandikos/web.py", line 1489, in xandikos_handler
    return await main_app.aiohttp_handler(request, options.route_prefix)
  File "/code/xandikos/webdav.py", line 2152, in aiohttp_handler
    response = await self._handle_request(request, environ)
  File "/code/xandikos/webdav.py", line 2108, in _handle_request
    return await do.handle(request, environ, self)
  File "/code/xandikos/webdav.py", line 1720, in handle
    (new_name, new_etag) = await r.create_member(
  File "/code/xandikos/web.py", line 407, in create_member
    (name, etag) = self.store.import_one(name, content_type, contents)
  File "/code/xandikos/store/git.py", line 335, in import_one
    etag = self._import_one(name, fi.normalized(), message, author=author)
  File "/code/xandikos/store/git.py", line 720, in _import_one
    self._commit_tree(
  File "/code/xandikos/store/git.py", line 695, in _commit_tree
    return self.repo.do_commit(message=message, author=author, tree=tree)
  File "/usr/lib/python3/dist-packages/dulwich/repo.py", line 960, in do_commit
    committer = get_user_identity(config, kind="COMMITTER")
  File "/usr/lib/python3/dist-packages/dulwich/repo.py", line 229, in get_user_identity
    user = default_user.encode("utf-8")
AttributeError: 'NoneType' object has no attribute 'encode'
172.19.0.2 [04/Sep/2023:06:37:56 +0000] "PUT /user/calendars/E592F3C6-82AA-43B6-94CD-3A59862A212C/E92E2C81-B8A8-4CC7-94D4-D1674AA90FF8.ics HTTP/1.1" 500 245 "-" "macOS/13.4.1 (22F82) dataaccessd/1.0"

My docker-compose.yml file is:

$ cat docker-compose.yml
version: '3.7'

services:
  xandikos:
    image: ghcr.io/jelmer/xandikos
    container_name: xandikos
    user: "1090:1090"
    restart: unless-stopped
    volumes:
      - /data/xandikos:/data

networks:
  default:
    external:
      name: caddy_network

Caddy is proxypassing all traffic on my chosen subdomain to the xandikos container with config like:

$ cat Caddyfile

xandikos.example.com:443 {
    basicauth {
        user $hunter2$
    }
    reverse_proxy xandikos:8000
}

I see the same xandikos error with and without the basicauth setup in Caddy.

jelmer commented 1 year ago

Xandikos should provide a better error message in this case - the issue is that it and Dulwich can't determine a default committer identity.

You can probably address this issue by setting a git identity (full name/email) in ~/.gitconfig

d5ve commented 1 year ago

Cheers @jelmer

I'd just come to a similar conclusion, and got things working by setting some ENV vars inside the container. I stepped through the code in Dulwich to find out where the default username and email were coming from.

See the USERNAME and EMAIL lines below. After this change, I was able to sucessfully write new calendar events.

$ cat docker-compose.yml

version: '3.7'

services:
  xandikos:
    image: ghcr.io/jelmer/xandikos
    container_name: xandikos
    user: "1090:1090"
    environment:
      - USERNAME=d5ve
      - EMAIL="d5ve@example.com"
    restart: unless-stopped
    volumes:
      - /data/xandikos:/data

Thanks for your prompt support for this neat project.

jelmer commented 1 year ago

reopening this to track the improved error message

jelmer commented 1 year ago

Fixed in dulwich