Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileOpen always give warning after last update #879

Closed
FileEX opened this issue Apr 22, 2019 · 2 comments
Closed

fileOpen always give warning after last update #879

FileEX opened this issue Apr 22, 2019 · 2 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@FileEX
Copy link
Contributor

FileEX commented Apr 22, 2019

Describe the bug
fileOpen function always give warning

Bad usage @ 'open' [unable to load file]

This function give warning about unable load file but open him and can read etc.... See code to reproduce, print will return file content.

To reproduce

local structure = {
	language = '?',
}

addEventHandler('onClientResourceStart', resourceRoot, function()
	if not fileExists('data/config.txt') then
		local file = fileCreate('data/config.txt');
		fileWrite(file, toJSON(structure));
		fileClose(file);
	end
	--[[local file = File.exists('data/config.cfg');
	if not file then
		file = File.new('data/config.cfg');
		file:write(toJSON(structure));
		file:close();
	end]]
end);

function applyData(key, value)
	local file = fileOpen('data/config.txt');
	if file then
		local d = fromJSON(fileRead(file, fileGetSize(file)));
		print(d[key]);

		fileClose(file);
	end
	--[[local f = File.open('data/config.cfg', false);
	local d = fromJSON(f:read(f.size));

	if d[key] then
		d[key] = value;
		f.pos = 0;
		f:write(toJSON(unpack(d)));
	end

	f:close();]]
end

applyData('language', 'a');

Expected behaviour
Fix this function

Screenshots
image

Version
1.5.6

Additional context

@FileEX FileEX added the bug Something isn't working label Apr 22, 2019
@qaisjp
Copy link
Contributor

qaisjp commented Apr 24, 2019

I think your example warns because applyData is called before the onClientResourceStart event is fired

@LosFaul
Copy link
Contributor

LosFaul commented Apr 24, 2019

applyData('language', 'a') is called before the event "onClientResourceStart" is fired
so your applyData function tries to open/read/close/... a non existing file

@FileEX FileEX closed this as completed Apr 25, 2019
@patrikjuvonen patrikjuvonen added the invalid This doesn't seem right label Apr 27, 2019
@lopezloo lopezloo closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants