Skip to content

Bug: setURL_ crashes with NSInvalidArgumentException - expects NSURL, receives Python string #23

@XuanyouLiu

Description

@XuanyouLiu

Bug Description

When creating or updating a calendar event with a url field, the server crashes with:

NSInvalidArgumentException - [OC_BuiltinPythonUnicode absoluteString]: unrecognized selector sent to instance

Root Cause

EKEvent.setURL_() expects an NSURL object (from Apple's Foundation framework), but the current code passes a raw Python string directly via PyObjC.

In src/mcp_ical/ical.py:

# Line 99 (create_event)
ekevent.setURL_(new_event.url)  # new_event.url is a Python str

# Line 168 (update_event)
existing_ek_event.setURL_(request.url)  # request.url is a Python str

When macOS tries to call absoluteString on the Python string (expecting it to be an NSURL), it fails because Python strings don't have that Objective-C method.

Steps to Reproduce

  1. Start the MCP server
  2. Create or update an event with a URL field, e.g.:
  3. Observe the NSInvalidArgumentException crash

Expected Behavior

The URL should be set on the calendar event without errors.

Fix

Convert the Python string to NSURL before passing to setURL_():

from Foundation import NSURL

# create_event
ekevent.setURL_(NSURL.URLWithString_(new_event.url))

# update_event
existing_ek_event.setURL_(NSURL.URLWithString_(request.url))

Environment

  • macOS 15 (Sequoia)
  • Python 3.12
  • PyObjC (latest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions