On 10/12/2012 11:20 AM, Alexander Bokovoy wrote:
On Thu, 11 Oct 2012, Petr Viktorin wrote:
On 10/11/2012 02:44 PM, Alexander Bokovoy wrote:
On Thu, 11 Oct 2012, Petr Viktorin wrote:
On 10/11/2012 12:27 PM, Alexander Bokovoy wrote:
On Thu, 11 Oct 2012, Petr Viktorin wrote:
On 10/08/2012 02:22 PM, Alexander Bokovoy wrote:
On Mon, 08 Oct 2012, Petr Vobornik wrote:
On 10/05/2012 08:14 PM, Alexander Bokovoy wrote:
On Fri, 05 Oct 2012, Petr Vobornik wrote:
On 10/05/2012 03:24 PM, Alexander Bokovoy wrote:
On Fri, 05 Oct 2012, Petr Vobornik wrote:
On 10/04/2012 05:06 PM, Alexander Bokovoy wrote:


two attached patches attempt to solve

We cannot make educated guess where trusted domain's DNS
server is
located as we ended up with NotFound exception precisely
because we
unable to discover trusted domain's domain controller

Thus, all we can do is to suggest ways to fix the issue. Since
suggestion becomes relatively long (multi-line, at least), it
few issues for current exception error message handling:
- root_logger does not use textui to format output
- textui is only printing to standard output
- multi-line error messages thus become non-wrapped
- localizing such messages would become a harder context-wise.

Web UI is showing error message as a single paragraph (<p/>),
multi-line markup would be lost.

In the end, I decided to support list-based multi-line error
messages in
PublicError class. Its constructor will join all list-based
into single string per argument (first patch).

In Web UI I've added special text processing of error messages
splits message into multiple lines and wraps those which start
with a
TAB symbol into 'error-message-hinted' span to visually
separate it
the rest of error message. Trust code uses this to display
suggested CLI
command to set up DNS forwarder (second patch).

In the end, CLI shows such error message fine (note tabulated

# ipa trust-add --type=ad --admin Administrator@ad.local1
Active directory domain administrator's password: ipa: ERROR:
Unable to
resolve domain controller for 'ad.local1' domain. IPA manages
please configure forwarder to 'ad.local1' domain by using
command. Please replace DNS_SERVER and IP_ADDRESS by name and
address of
the domain's name server:
ipa dnszone-add ad.local1 --name-server=DNS_SERVER
--admin-email='hostmaster@ad.local1' --force
When using Web UI, please create DNS zone for domain
and then set forwarder and forward policy

Web UI looks like this:

You have undeclared identifier: lines.

I recommend to run `jsl -conf jsl.conf` command in install/ui
to prevent these issues.

I'm not convinced that "beautify" call should be in command
object. I
would rather see it in error_dialog.
I moved everything to error_dialog and used $() selectors
instead of
directly playing with text.

+        var error_message = $('<span />', {});

I would rather see a <div /> as a container. Span is and should
contain only inline elements.

var line_span = $('<span />', {
               class: 'error-message-hinted',
               text: lines[i].substr(1)

Why do you use <span> for hinted message and <p> for other lines?
Shouldn't we use <p> for both?
Fixed to use <p> everywhere.

3) var line_span is declared twice. JS use function scope, not

Thanks for the review. New patch 0082 attached.

ACK on the UI part with a little change (updated patch attached):
class: 'error-message-hinted',
needs to be changed to
'class': 'error-message-hinted',
because class is a keyword and should not be used this way. Sorry
I missed it before.

The patch works as advertised. I would give ACK to the python
part of
82 and patch 83 as well but probably someone more skilled in python
and ipa internals should do it.

Why do you have to concatenate the value in PublicErrors' __init__
method? Shouldn't it be a responsibility of error source (in this
'execute_ad' method)? - just a question, not an issue
This is a good question and gives me some space to explain why
decisions are made.

The whole idea of the patch is to introduce a way to provide
error messages as a feature of error handling in the FreeIPA

Suppose we had to join multiple lines always before creating an
object. This means we would have hundreds of '\n'.join() calls
the code. Besides maintenance burden, it would also make
burden later if we would add proper content formating (which we
don't do
now for errors) -- since we would need to split strings later to
reformat them.

Python is flexible enough to discover parameter types which
allows to design APIs that easer to use. "Easier to use" means least
surprise for the caller rather than callee. So, if you pass multiple
lines (list) of error message, each array element gets processed
separately before displaying.
So, in the end there is only one place where this processing
and it encapsulates all the knowledge required to accept multi-lines
messages, regardless how they come, since it is applied uniformly to
argument of a constructor of a PublicError-derived class.

Some of our errors already accept lists. From our doctest suite:

File "/home/pviktori/freeipa/ipalib/errors.py", line 731, in
Failed example:
 raise OverlapError(names=['givenname', 'login'])
 Traceback (most recent call last):
 OverlapError: overlapping arguments and options: ['givenname',
 Traceback (most recent call last):
   File "/usr/lib64/python2.7/doctest.py", line 1289, in __run
     compileflags, 1) in test.globs
   File "<doctest ipalib.errors.OverlapError[0]>", line 1, in
     raise OverlapError(names=['givenname', 'login'])
 OverlapError: overlapping arguments and options: u'givenname\nlogin'

In this case, ['givenname', 'login'] is much better than
u'givenname\nlogin' (or givenname<newline>login, if we switched the
message from %r to %s).

I don't think what's best for trust-add's NotFound is the best thing
to do everywhere.
Sure. Could you make a ticket so that I can investigate it more and
appropriate way to handle this? Perhaps an error class could define
it wants to treat its arguments?

Sure. Please share findings of your investigation, then.


Basically, I think you generalized too much. The result is much more
complex (=less understandable, maintainable, changeable) than a
'\n'.join() when creating the error.

With the following patch I have this behavior:
from ipalib import errors
raise errors.PublicError(lines=['foo','bar'], format="You've got a
message: %(lines)s")
Traceback (most recent call last):
 File "<console>", line 1, in <module>
PublicError: You've got a message: foo
raise errors.OverlapError(names=['foo','bar'])
Traceback (most recent call last):
 File "<console>", line 1, in <module>
OverlapError: overlapping arguments and options: ['foo', 'bar']

The new patch adds even more complexity. Adding the conversions only
to error classes that need them (if any), as opposed to PublicError
with an option to turn them off, would be much more straightforward.
After discussing more with Petr on irc, I came up with the following
patch: allow `instructions' additional parameter to PublicError() to
add instructions to an error message.

Trust's error message is converted to show its use.

The rationale:
The need for multi-line error messages was prompted by requests that
IPA should either fix/prevent errors itself, or print out more
detailed instructions for the user.
Automatic joining of lists is problematic, because it repurposes a
standard datatype for the needs of a fairly specific use case.
Converting individual arguments that need it is better than a blanket
An extra argument for instructions allows us to separate the error
message and instructions in the future, if we need to e.g. add more
complex formatting than the \t.

Patch comments:
This needs some tests to verify it's right and prevent regressions.
Please rename the convert_keyword function to e.g. format_instructions.
It's not necessary to add the instructions to self.msg, that one is
not user-friendly.
Please wrap the long line in errors.py.
Updated the patch with new test case and fixes. Also split out trust.py
changes to a separate patch.

Both attached.

This works, however the test regexp doesn't do what it claims (doesn't check if each string is on a separate line). Checking the entire message would make the test more straightforward. Squash in the attached patch if you agree. I haven't tested the ipa-trust-add code as I don't have an AD machine, but it looks good.


diff --git a/tests/test_ipalib/test_errors.py b/tests/test_ipalib/test_errors.py
index 1421e7844a7068605568bccf78715669dfe0d8ec..23466af43dc3603730ec4119f8045f087fa9dc3a 100644
--- a/tests/test_ipalib/test_errors.py
+++ b/tests/test_ipalib/test_errors.py
@@ -323,17 +323,13 @@ class subclass(self.klass):
         # lines of instructions appended to the end of the strerror
         # despite the parameter 'instructions' not existing in the format
         instructions = u"The quick brown fox jumps over the lazy dog".split()
-        # this expression checks if each word of instructions
-        # exists in a string as a separate line, with right order
-        regexp = re.compile('(?ims).*' +
-                            ''.join(map(lambda x: '(%s).*' % (x),
-                                        instructions)) +
-                            '$')
         inst = subclass(instructions=instructions, **kw)
         assert inst.format is subclass.format
         assert_equal(inst.instructions, instructions)
-        inst_match = regexp.match(inst.strerror).groups()
-        assert_equal(list(inst_match),list(instructions))
+        expected_strerror = '\n'.join(
+            [subclass.format % kw, "Additional instructions:"] +
+            instructions)
+        assert_equal(unicode(inst.strerror), expected_strerror)
 def test_public_errors():
Freeipa-devel mailing list

Reply via email to