winapi icon indicating copy to clipboard operation
winapi copied to clipboard

Errors in watch_for_file_changes are handled by crashing

Open blobbyblob opened this issue 7 years ago • 0 comments

When an error is encountered in the callback for watch_for_file_changes, the program will crash saying lua5.1.exe has stopped working rather than providing a useful error message. Repro:

require("winapi")

watcher, err = winapi.watch_for_file_changes(
	".",
	winapi.FILE_NOTIFY_CHANGE_LAST_WRITE,
	false,
	function() oops_not_a_function(); end
);

local file = io.open("out.txt", "w")
file:write("foobar")
file:close()

winapi.sleep(100)

A similar experience can be had by passing in nil for the function callback.

It would be much more useful if the error would be handled like errors encountered during regular execution, that is, providing a message: "test.lua:7: attempt to call global 'oops_not_a_function' (a nil value)"

blobbyblob avatar May 12 '18 16:05 blobbyblob