[Kimchi-devel] [PATCH 0/3 RFC] Refactor exception

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 31 18:20:50 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

Hi all,

This is the RFC for the refactor exception task.
Sheldon has already done something related to that some time ago.

He also created a wiki for that:
    - https://github.com/kimchi-project/kimchi/wiki/refactor-exception

The only change I made in him approach is translating the message in backend
and send it to UI
That way we don't need to duplicate the messages on backend and UI (as it is 
explained on wiki)

The steps to get it done:
1) Change cherrypy error handler to send the exception data to UI
2) Create a common Exception class (KimchiError) to translate the error message
   and proper set the parameters
3) Update UI to show the message received from backend to the user

I also would like to create a file on backend: __messages__.py which will
contain all messages used on backend.
For example:

# __messages__.py
VM_START_FAILED = "<code>: Failed to start virtual machine %(name)s"

The contants names should be: <resource>_<action>_<error>

The <code> need to be a unique value between all messages.
It is needed in order to we identify the error independent of the message
language.
That way a user running Kimchi in German can easily post his error on mail list
or github, and we can identify where the problem is by the message code.

I also will add this code in the UI messages.

For the code, we can build it like: <resource><BACK|UI><type-of-error><ident>
And on backend:

VMBACKINFO01
VMBACKERRO01
VMBACKWARN01

And on UI:

VMUIINFO01
VMUIERRO01
VMUIWARN01

So we will also need:
4) Create a __messages__ file with all messages used on backend
5) Update build process to add the messages in this file to .po files
6) Update UI messages to add a code for them

I made a small patch set with my proposal.
This patch set does not include the items 4,5 and 6
In fact, I used an existent message for test (as you can notice on patches)
And *just for example* it will *always* raise an exception while starting a VM.

Any comments/suggestions are welcome. =)

Aline Manera (2):
  refactor exception: Create a common Exception to translate error
    messages
  refator exception: Example of use

ShaoHe Feng (1):
  refactor exception: Add a kimchi special error handler

 src/kimchi/control/base.py     |    5 ++++-
 src/kimchi/exception.py        |   29 ++++++++++++++++++++++-------
 src/kimchi/model/vms.py        |    4 +++-
 src/kimchi/template.py         |   14 ++++++++++++++
 ui/js/src/kimchi.guest_main.js |    4 ++--
 5 files changed, 45 insertions(+), 11 deletions(-)

-- 
1.7.10.4




More information about the Kimchi-devel mailing list