Skip to content

Crash: attempt to compare nil with number in clear_items (job.lua:879) #1

@ILLISIS

Description

@ILLISIS

Error

Error while running event level::on_nth_tick(90)
__level__/modules/ctron_plugin/script/job.lua:879: attempt to compare nil with number
stack traceback:
  job.lua:879: in function 'clear_items'
  job.lua:1187: in function '?'
  job.lua:1055: in function 'execute'
  job_processor.lua:26: in function 'process_job_queue'
  control.lua:39: in function 'handler'
  lualib/event_handler.lua:81: in function
  lualib/event_handler.lua:79

Root Cause

In job.lua:879, logistic_network is accessed without a nil check:

local logistic_network = self.station.logistic_network  -- can be nil
if (logistic_network.all_logistic_robots <= 0) then     -- crashes if nil

If the station has no logistic network (e.g. the network was removed or the station is not inside one), self.station.logistic_network returns nil, and the comparison on line 879 throws a non-recoverable error.

Expected Behavior

A nil check on logistic_network before accessing its fields, similar to the existing check on line 882 (if not next(logistic_network.storages)), should guard line 879 as well.

Suggested Fix

local logistic_network = self.station.logistic_network
if not logistic_network then
    debug_lib.VisualDebugText({"ctron_status.no_logi_robots"}, worker, -0.5, 3)
elseif (logistic_network.all_logistic_robots <= 0) then
    debug_lib.VisualDebugText({"ctron_status.no_logi_robots"}, worker, -0.5, 3)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions