Re: Maybe too strict check for frontend/backend name conflicts

From: Willy Tarreau <w#1wt.eu>
Date: Sat, 3 Nov 2007 11:17:58 +0100


On Sat, Nov 03, 2007 at 02:47:19AM +0100, Krzysztof Oledzki wrote:
> >>How about adding a global "char errstr[BUFSIZE]"? Each function can then
> >>easily return a appropriate error message. No need to pass additional
> >>buffers and lengths.
> >
> >That's what I thought about first, then I realized that it would not be
> >convenient for intermediate functions to prefix the error messages with
> >their part of context. For instance, such a message could be completed
> >by 4 different levels :
> >
> >"Proxy xxx: rule yyy: acl zzz requires HTTP mode"
> > <--- level 4 ---->
> > <------- level 3 -------->
> > <------------ level 2 ------------->
> ><------------------ level 1 ------------------>
> >
> >So in certain circumstances, the error message will be on the caller's
> >stack.
>
> Oh, indeed. But this still can be solved without passing
> additional references. Attached example code that produces:
>
> "Proxy xxx: rule yyy: acl zzz requires HTTP mode"

Your example does not solve every case. It assumes that the messages are completed from deeper to outer level only. But in many cases (mainly for outer levels), we'd prefer to pre-initialize the error prefix before calling the inner functions, in order to avoid having to do this in every if/else statement.

I'm still thinking about this, but I believe that what we need is a stack or text fragments that can be fed by all the functions. We would then only pass to each function the stack level (most always 'level+1'). We would then have two functions:

We would also need a collapse function to merge many levels into one, which is handy when you need to merge the message inside another one :

Example:

int f1(int level) {

   int ret;

   init_error_stack(level, "In f1:");
   ret = f2(level+1);

   if (ret < 0)

       return ret; // keeps err stack
   else if (ret == ERR1) {

       set_error_msg(level, "Critical error in f1:");  // keeps f2's error
       return ret;

   }
   else if (ret == ERR2) {
       collapse_error_levels(level+1);
       sprintf(msg[level], "Error in f1: %s. Retry later", msg[level+1]);
       return ret;

   }
   ...
}

I think it covers all required cases without too much hassle. It evens supports error control transfer from f1 to f2 that way :

     return f2(level);

> However, for long messages I think multi-line output may be better:
> Refusing to use duplicated proxy 'aqq1' with conflicting capabilities:
> backend/backend!
> Proxy 'www.example.com': unable to find required default_backend: 'aqq1'.

I agree, but it is important in this case to indent the message so that we can count them. There are example of multi-line warnings which already do this. Also, maybe this should be a decision of the display function. Indeed, when sending errors to logs, it's important to keep them on one single line.

Regards,
Willy Received on 2007/11/03 11:17

This archive was generated by hypermail 2.2.0 : 2007/11/04 19:21 CET