General > Developers Corner

ULib attempt to index 'str' (a nil value): praseKeyValues; removeCommentHeader

(1/1)

Imperial Knight:
Hey.

So with an addon I'm working on, it appears I get ulib errors on some of ulib's functions, for some reason. I'll provide each line of code for the error.

addons/ulib/lua/ulib/shared/misc.lua:30 (ULib Code)

--- Code: ---local newpos, endpos = str:find( separator, curpos ) -- find the next separator in the string

--- End code ---

addons/ulib/lua/ulib/shared/misc.lua:696 (ULib Code)

--- Code: ---local lines = ULib.explode( "\r?\n", data )

--- End code ---

addons/imbans/lua/autorun/server/ulx_sv_mysql.lua:915 (My Code)

--- Code: ---local bans, error3 = ULib.parseKeyValues( ULib.removeCommentHeader( ULib.fileRead( ULib.BANS_FILE ), "/" ) )

--- End code ---

lua/includes/modules/concommand.lua:54 (Garry's Mod Dedicated Server Code)

--- Code: ---CommandList[ LowerCommand ]( player, command, arguments, args )

--- End code ---

I'm a bit confused as to why it's erroring out there. (I've provided the error below)


My ULib/ULX versions (run "ulx version" in console):
ULib v2.61 (latest as of now)
ULX v3.71 (latest as of now)

Game mode(s) I am having this problem on: Not relevant: any gamemode.

Lua errors shown in console, if any:

--- Code: ---[ERROR] addons/ulib/lua/ulib/shared/misc.lua:30: attempt to index local 'str' (a
 nil value)
  1. explode - addons/ulib/lua/ulib/shared/misc.lua:30
   2. removeCommentHeader - addons/ulib/lua/ulib/shared/misc.lua:696
    3. unknown - addons/imbans/lua/autorun/server/ulx_sv_mysql.lua:915
     4. unknown - lua/includes/modules/concommand.lua:54

--- End code ---

Any help or suggestions with this would be greatly appreciated. If this is an actual issue on ULib's side, I'll create a bug report.

Timmy:

--- Code: ---local bans, error3 = ULib.parseKeyValues( ULib.removeCommentHeader( ULib.fileRead( ULib.BANS_FILE ), "/" ) )
--- End code ---

Are you checking if ULib.BANS_FILE (data/ulib/bans.txt) exists before trying to read it? ULib.fileRead will return nil if the file does not exist. That would cause the other functions to fail, as they expect a string type argument.

You can refer to the source code for ULib.refreshBans to see how ULib loads bans.

Imperial Knight:
Thanks for the reply.

The problem I was having was an addon (custom ban message addon somehow) that was stopping ULX from creating a bans.txt file and instead read the garrysmod/cfg/banned_user.cfg file, which messed with the ULib.BAN_FILE.

Navigation

[0] Message Index

Go to full version