Branch: Tag:

2010-09-06

2010-09-06 13:32:45 by Martin Stjernholm <mast@lysator.liu.se>

Added a hint about the type attribute to the infamous "Cannot append another
value ... to non-sequential type any" message (and similar errors).

Rev: server/etc/modules/RXML.pmod/utils.pmod:1.36
Rev: server/etc/test/tests/rxml/RoxenTest_RXMLTags.xml:1.66

7:   //!   //! Created 2000-01-21 by Martin Stjernholm   //! - //! $Id: utils.pmod,v 1.35 2008/10/12 22:14:03 mast Exp $ + //! $Id: utils.pmod,v 1.36 2010/09/06 13:32:45 mast Exp $    -  + #define RXML_CONTEXT (_cur_rxml_context->get()) +    constant is_RXML_encodable = 1;      #ifdef RXML_ENCODE_DEBUG
86:   final mapping(string:string) return_help_arg (mixed... ignored)    {return (["help": "help"]);}    + protected string type_attribute_hint (RXML.Type type) + { +  // If this happens for t_any inside a <set> or <append> without any +  // type attribute, it's probably the common pitfall with the default +  // type for those tags. +  if (type == RXML.t_any) +  if (RXML.Context ctx = RXML_CONTEXT) +  if (ctx->frame && (<"set", "append">)[ctx->frame->tag->name] && +  zero_type (ctx->frame->args->type)) +  return "Maybe an attribute type=\"text/*\" is missing.\n"; +  return ""; + } +    final mixed get_non_nil (RXML.Type type, mixed... vals)   // Returns the single argument in vals that isn't RXML.nil, or   // RXML.nil if all of them are that value. Throws an rxml parse error
99:    for (pos++; pos < sizeof (vals); pos++)    if (vals[pos] != RXML.nil)    RXML.parse_error ( -  "Cannot append another value %s to non-sequential value of type %s.\n", -  format_short (vals[pos]), type->name); +  "Cannot append another value %s to non-sequential " +  "value of type %s.\n%s", +  format_short (vals[pos]), type->name, type_attribute_hint (type));    return res;   }   
108:   {    p->context->handle_exception (    catch (RXML.parse_error ( -  "Unknown tag %s is not allowed in context of type %s.\n", -  format_short (p->tag_name()), p->type->name)), +  "Unknown tag %s is not allowed in context of type %s.\n%s", +  format_short (p->tag_name()), p->type->name, +  type_attribute_hint (p->type))),    p, p->p_code);    return ({});   }
119:    sscanf (str, "%[^ \t\n\r]", str);    p->context->handle_exception (    catch (RXML.parse_error ( -  "Unknown processing instruction %s not allowed in context of type %s.\n", -  format_short ("<" + p->tag_name() + str), p->type->name)), +  "Unknown processing instruction %s not allowed " +  "in context of type %s.\n%s", +  format_short ("<" + p->tag_name() + str), p->type->name, +  type_attribute_hint (p->type))),    p, p->p_code);    return ({});   }
129:   {    p->context->handle_exception (    catch (RXML.parse_error ( -  "CDATA text %O is not allowed in context of type %s.\n", -  format_short (str), p->type->name)), +  "CDATA text %O is not allowed in context of type %s.\n%s", +  format_short (str), p->type->name, +  type_attribute_hint (p->type))),    p, p->p_code);    return ({});   }