]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/bugs/Error_with_external_plugins.mdwn
More info about the (possible) bug in the external plugin (RPC communication)
[git.ikiwiki.info.git] / doc / bugs / Error_with_external_plugins.mdwn
1 Hello,
2 I stumbled upon this bug when writing a Python plugin. I think this is a ikiwiki bug, since I do not think my plugin does anything wrong.
4 # Example
6 I set up an example wiki, containing the setup file and the plugin, [[on github|https://github.com/paternal/ikiwiki-rpcbug]].
8 1. Clone the repository
10         git clone https://github.com/paternal/ikiwiki-rpcbug.git
12 2. Change to the right directory
14         cd ikiwiki-rpcbug
16 2. Add the right ikiwiki directory to PYTHONPATH
18         export PYTHONPATH="$PYTHONPATH:$(dirname $(dpkg -L ikiwiki | grep proxy))"
20 3. Build the wiki
22         ikiwiki --setup wiki.setup --rebuild
24 4. The problem is in page [[http://localhost/~USERNAME/ikiwiki_bug_rpc/foo/]] (for instance, [[http://localhost/~USERNAME/ikiwiki_bug_rpc]] is fine.
26 # Problem
28 Page `foo` contains the directive ``[[!rpcbug]]`` (`rpcbug` being the name of the plugin). Calling [[``proxy.rpc("srcfile", "bar")``|https://github.com/paternal/ikiwiki-rpcbug/blob/master/plugins/rpcbug#L15]] in the preprocess function seems to mess up the RPC communication between ikiwiki and the plugin, and the result is that the generate `foo/index.html` page is a text file containing the return value of the `preprocess` call.
30 What I do not understand is that disabling the `format` function (by commenting [[line 46 of the plugin|https://github.com/paternal/ikiwiki-rpcbug/blob/master/plugins/rpcbug#L46]]) solves the problem. Half of an explaination is that I think that when the the ``proxy.rpc`` function is called, the RPC communication is messed up in such a way that the `format` function is not called, and the return value of `preprocess` is considered to be the whole html code of the resulting page.
32 > I understood that: as the first rpc call messes up the communication, more rpc calls are messed up, but if there is only one rpc call, not that much is broken. -- [[Louis|spalax]]
34 I hope someone will understand the problem better than I do, because I have no idea about how to solve this.
36 Regards,    
37 -- [[Louis|spalax]]
39 > I wrote a plugin to monitor what is exchanged between the plugin and Ikiwiki. I ran this with [this version](https://github.com/paternal/ikiwiki-rpcbug/tree/b4ba34a8edd1b97989965af69eddac050bc0a8ba) of my minimal bug example.
40
41 > * The bug happens in function [preprocess](https://github.com/paternal/ikiwiki-rpcbug/blob/b4ba34a8edd1b97989965af69eddac050bc0a8ba/plugins/rpcbug#L12-17) (in call to [srcfile](https://github.com/paternal/ikiwiki-rpcbug/blob/b4ba34a8edd1b97989965af69eddac050bc0a8ba/plugins/rpcbug#L15), to be more precise).
42 > * The directive causing the bug is called on page [foo](https://github.com/paternal/ikiwiki-rpcbug/blob/b4ba34a8edd1b97989965af69eddac050bc0a8ba/foo.mdwn).
43 > * Communication between Ikiwiki and the plugin is [[here|tee]].
44 > * The resulting HTML (for page `foo`) looks like:
45
46 > > \[[!rpcbug Erreur: internal error: foo cannot be found in /home/louis/projets/ikiwiki/rpcbug or underlay]]
47 > >
48 > >
49 > > Calling srcfile(foo): page    
50 > > Calling srcfile(README.md): /home/louis/projets/ikiwiki/rpcbug/README.md
51
52 > My analysis:
53
54 > * The call to `srcfile(foo)` fails (because Ikiwiki thinks that page `foo` does not exist).
55 > * Ikiwiki thinks that processing of the directive is finished, whereas the plugin still waits for the answer of Ikiwiki.
56 > * Ikiwiki asks the plugin to render a new directive, but the plugin interprets the request as the return value for its previous request. Thus, the plugin thinks that `srcfile(foo)` is `page` (this `page` being a misinterpretation of the Ikiwiki request).
57
58 > So, I think that this might be an error in the
59 > [`rpc_call`](https://github.com/joeyh/ikiwiki/blob/9476e2ac7ad2f53643fa2fca6ba35fcc55ab058e/IkiWiki/Plugin/external.pm#L46-147)
60 > function of the `external` plugin: when the called method fails, it should
61 > return something (or raise an exception, if this is possible in RPC) to notify
62 > the plugin that something went wrong.
63
64 > -- [[Louis|spalax]]