diff --git a/jed.js b/jed.js index b9218bb..4faae96 100644 --- a/jed.js +++ b/jed.js @@ -451,12 +451,12 @@ in order to offer easy upgrades -- jsgettext.berlios.de field_list.push(field_match[1]); } else { - throw('[sprintf] huh?'); + throw('[sprintf] Named placeholders should only contain valid identifiers.'); } } } else { - throw('[sprintf] huh?'); + throw('[sprintf] Named placeholders should only contain valid identifiers.'); } match[2] = field_list; } @@ -464,12 +464,12 @@ in order to offer easy upgrades -- jsgettext.berlios.de arg_names |= 2; } if (arg_names === 3) { - throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + throw('[sprintf] mixing positional and named placeholders is not (yet) supported.'); } parse_tree.push(match); } else { - throw('[sprintf] huh?'); + throw('[sprintf] Found percentage-sign, but it wasn\'t a valid placeholder or escaped percentage-sign.'); } _fmt = _fmt.substring(match[0].length); } diff --git a/test/tests.js b/test/tests.js index 7ebc8c0..4b027d1 100644 --- a/test/tests.js +++ b/test/tests.js @@ -740,6 +740,11 @@ expect(i18n.sprintf(i, arg)).to.be(strings[i]); } }); + + it("should give meaningfull error messages", function() { + expect(Jed.sprintf.bind(null, "5%", {})).to.throwException(/^\[sprintf\] Found percentage-sign, but it wasn't a valid placeholder or escaped percentage-sign.$/); + expect(Jed.sprintf.bind(null, "%(1invalid)s", {})).to.throwException(/^\[sprintf\] Named placeholders should only contain valid identifiers.$/); + }); }); })();