diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts index 880649f4..d7f54ac4 100644 --- a/src/compiler/code_generator.ts +++ b/src/compiler/code_generator.ts @@ -30,6 +30,7 @@ import { Attrs, EventHandlers, } from "./parser"; +import { OwlError } from "../runtime/error_handling"; type BlockType = "block" | "text" | "multi" | "list" | "html" | "comment"; @@ -535,7 +536,7 @@ export class CodeGenerator { .slice(1) .map((m) => { if (!MODS.has(m)) { - throw new Error(`Unknown event modifier: '${m}'`); + throw new OwlError(`Unknown event modifier: '${m}'`); } return `"${m}"`; }); @@ -871,8 +872,9 @@ export class CodeGenerator { this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar); if (this.dev) { // Throw error on duplicate keys in dev mode + this.helpers.add("OwlError"); this.addLine( - `if (keys${block.id}.has(key${this.target.loopLevel})) { throw new Error(\`Got duplicate key in t-foreach: \${key${this.target.loopLevel}}\`)}` + `if (keys${block.id}.has(key${this.target.loopLevel})) { throw new OwlError(\`Got duplicate key in t-foreach: \${key${this.target.loopLevel}}\`)}` ); this.addLine(`keys${block.id}.add(key${this.target.loopLevel});`); } @@ -1094,7 +1096,7 @@ export class CodeGenerator { name = _name; value = `bind(ctx, ${value || undefined})`; } else { - throw new Error("Invalid prop suffix"); + throw new OwlError("Invalid prop suffix"); } } name = /^[a-z_]+$/i.test(name) ? name : `'${name}'`; diff --git a/src/compiler/inline_expressions.ts b/src/compiler/inline_expressions.ts index 21fcfcde..adcde781 100644 --- a/src/compiler/inline_expressions.ts +++ b/src/compiler/inline_expressions.ts @@ -1,3 +1,5 @@ +import { OwlError } from "../runtime/error_handling"; + /** * Owl QWeb Expression Parser * @@ -106,14 +108,14 @@ let tokenizeString: Tokenizer = function (expr) { i++; cur = expr[i]; if (!cur) { - throw new Error("Invalid expression"); + throw new OwlError("Invalid expression"); } s += cur; } i++; } if (expr[i] !== start) { - throw new Error("Invalid expression"); + throw new OwlError("Invalid expression"); } s += start; if (start === "`") { @@ -223,7 +225,7 @@ export function tokenize(expr: string): Token[] { error = e; // Silence all errors and throw a generic error below } if (current.length || error) { - throw new Error(`Tokenizer error: could not tokenize \`${expr}\``); + throw new OwlError(`Tokenizer error: could not tokenize \`${expr}\``); } return result; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 540e4a70..4f3f39f7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1,3 +1,5 @@ +import { OwlError } from "../runtime/error_handling"; + // ----------------------------------------------------------------------------- // AST Type definition // ----------------------------------------------------------------------------- @@ -319,7 +321,7 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null { return null; } if (tagName.startsWith("block-")) { - throw new Error(`Invalid tag name: '${tagName}'`); + throw new OwlError(`Invalid tag name: '${tagName}'`); } ctx = Object.assign({}, ctx); if (tagName === "pre") { @@ -340,13 +342,15 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null { const value = node.getAttribute(attr)!; if (attr.startsWith("t-on")) { if (attr === "t-on") { - throw new Error("Missing event name with t-on directive"); + throw new OwlError("Missing event name with t-on directive"); } on = on || {}; on[attr.slice(5)] = value; } else if (attr.startsWith("t-model")) { if (!["input", "select", "textarea"].includes(tagName)) { - throw new Error("The t-model directive only works with ,