Skip to content

Commit c8ff987

Browse files
committed
Fixed some error handling stuff.
1 parent 9b6c751 commit c8ff987

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

preprocess.lua

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ function tryToFormatError(err0)
231231
local err, path, ln = nil
232232

233233
if type(err0) == "string" then
234-
path, ln, err = err0:match'^(.-):(%d+): (.*)'
235-
if not err then
236-
path, ln, err = err0:match'^([%w_/.]+):(%d+): (.*)'
237-
end
234+
do path, ln, err = err0:match'^(%a:[%w_/\\.]+):(%d+): (.*)'
235+
if not err then path, ln, err = err0:match'^([%w_/\\.]+):(%d+): (.*)'
236+
if not err then path, ln, err = err0:match'^(.-):(%d+): (.*)'
237+
end end end
238238
end
239239

240240
if err then
@@ -1073,9 +1073,9 @@ do
10731073
table.insert(errorHandlers, errHand)
10741074
currentErrorHandler = errHand
10751075
end
1076-
function pushErrorHandlerIfOverridingDefault(errHand)
1077-
pushErrorHandler(currentErrorHandler == _error and errHand or currentErrorHandler)
1078-
end
1076+
-- function pushErrorHandlerIfOverridingDefault(errHand) -- Unused.
1077+
-- pushErrorHandler(currentErrorHandler == _error and errHand or currentErrorHandler)
1078+
-- end
10791079
function popErrorHandler()
10801080
table.remove(errorHandlers)
10811081
if not errorHandlers[1] then
@@ -1552,8 +1552,11 @@ local function _processFileOrString(params, isFile)
15521552
if isFile then
15531553
if not params.pathIn then error("Missing 'pathIn' in params.", 2) end
15541554
if not params.pathOut then error("Missing 'pathOut' in params.", 2) end
1555+
1556+
if params.pathOut == params.pathIn then error("'pathIn' and 'pathOut' are the same in params.", 2) end
1557+
15551558
else
1556-
if not params.code then error("Missing 'code' in params.", 2) end
1559+
if not params.code then error("Missing 'code' in params.", 2) end
15571560
end
15581561

15591562
local luaUnprocessed, pathIn
@@ -2328,6 +2331,8 @@ local function processFileOrString(params, isFile)
23282331
if params.onError then params.onError(errorToReturn) end
23292332

23302333
if levelFromOurError then _error(ERROR_REDIRECTION) end
2334+
2335+
return err -- Not sure when this return matters. I have a feeling it's never. 2021-05-12
23312336
end
23322337

23332338
isDebug = params.debug
@@ -2353,7 +2358,8 @@ local function processFileOrString(params, isFile)
23532358

23542359
-- Unhandled error.
23552360
if not (returnValues or errorToReturn) then
2356-
pcall(errHand, (not xpcallOk and xpcallErr or "Unknown processing error."))
2361+
errorToReturn = (not xpcallOk and xpcallErr or "Unknown processing error.")
2362+
pcall(errHand, errorToReturn)
23572363
end
23582364

23592365
-- Handled error.

tests/runQuickTestUsingApi.cmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@ECHO OFF
2+
CD /D "%~dp0.."
3+
4+
IF NOT EXIST local MD local
5+
6+
lua tests/runQuickTestUsingApi.lua
7+
8+
IF %ERRORLEVEL% EQU 0 lua tests/quickTest.lua

tests/runQuickTestUsingApi.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
io.stdout:setvbuf("no")
2+
io.stderr:setvbuf("no")
3+
4+
local pp = require"preprocess"
5+
6+
local info, err = pp.processFile{
7+
pathIn = "tests/quickTest.lua2p",
8+
pathOut = "tests/quickTest.lua",
9+
pathMeta = "tests/quickTest.meta.lua",
10+
debug = true,
11+
}
12+
13+
if not info then
14+
print("Processing failed!")
15+
os.exit(1)
16+
end

0 commit comments

Comments
 (0)