> postgres=# do $$ > x = plpy.SPIError('Nazdarek'); > x.spidata = (100, "Some detail", "some hint", None, None); > raise x; > $$ language plpythonu;
Shouldn't that look more like
raise plpy.SPIError(msg="Message", sqlstate="0P001", hint="Turn it on and off again") ?
Keyword args are very much the norm for this sort of thing. I recall them being pretty reasonable to deal with in the CPython API too, but otherwise a trivial Python wrapper in the module can easily adapt the interface.
I wrote a constructor for SPIError with keyword parameters support - see attached patch
The code is working
postgres=# do $$ raise plpy.SPIError("pokus",hint = "some info"); $$ language plpythonu; ERROR: plpy.SPIError: pokus HINT: some info CONTEXT: Traceback (most recent call last): PL/Python anonymous code block, line 2, in <module> raise plpy.SPIError("pokus",hint = "some info"); PL/Python anonymous code block
but the implementation is pretty ugly :( - I didn't write C extensions for Python before, and the extending exception class with some methods isn't well supported and well documented.