tools/ejabberdsql2prosody: Track current line for error reporting
authorMatthew Wild <mwild1@gmail.com>
Tue, 20 Sep 2011 22:30:58 +0000 (23:30 +0100)
committerMatthew Wild <mwild1@gmail.com>
Tue, 20 Sep 2011 22:30:58 +0000 (23:30 +0100)
tools/ejabberdsql2prosody.lua

index 958cf0e2d1c97ec027e7bb71ab4dcab684f6f890..576f44366ab01d9aa84c307a03cc2de17df3bf86 100644 (file)
@@ -21,12 +21,16 @@ function parseFile(filename)
 
 local file = nil;
 local last = nil;
+local line = 1;
 local function read(expected)
        local ch;
        if last then
                ch = last; last = nil;
-       else ch = file:read(1); end
-       if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end
+       else
+               ch = file:read(1);
+               if ch == "\n" then line = line + 1; end
+       end
+       if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil").." on line "..line); end
        return ch;
 end
 local function pushback(ch)