Bug on Portlet validation

Are there any example on how to validate a portlet field?

I tried to use the constraint attribute, but portlet input form is not treating the Invalid exception and showing the error message.. it gives me this traceback:

Traceback (innermost last):

Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module plone.app.portlets.browser.formhelper, line 126, in __call__
Module zope.formlib.form, line 868, in __call__
Module five.formlib.formbase, line 50, in update
Module zope.formlib.form, line 835, in update
Module zope.formlib.form, line 724, in handleSubmit
Module zope.formlib.form, line 813, in validate
Module zope.formlib.form, line 354, in getWidgetsData
Module zope.formlib.widget, line 417, in getInputValue
Module zope.schema._bootstrapfields, line 182, in validate
Module zope.schema._bootstrapfields, line 309, in _validate
Module zope.schema._bootstrapfields, line 211, in _validate
Module collective.blueline.interfaces, line 32, in validCodeConstraint
Invalid: Invalid code: Tag asdf invalid, line 1, column 6

This is the code of the constraint I'm using:

def validCodeConstraint(value):
    """Validate code inserted into control panel configlet fields.
    :param value: code to be validated
    :type value: unicode
    :return: True if code is valid
    :rtype: bool
        :class:`~zope.interface.Invalid` if the code is not valid
    if value:
        parser = etree.HTMLParser(recover=False)
            etree.HTML(value, parser)
        except Exception as e:
            raise Invalid(_(u'Invalid code: ') + e.message)
    return True

class IBluelinePortlet(IPortletDataProvider):

    '''Blueline Portlet.'''

    embed = schema.Text(
        title=_(u'Embedding code'),

You're mixing things and rising the wrong exception:

class InvalidHTMLCode(ValidationError):
    """The code is invalid."""

def validateHTMLCode(code):
    """Validate code inserted into portlet."""
    if code:
        parser = etree.HTMLParser(recover=False)
            etree.HTML(code, parser)
        except etree.XMLSyntaxError:
            raise InvalidHTMLCode
    return True

Check the documentation for more information.

@hvelarde thank you, I didn't find the right documentation.