Advanced Peripherals

Advanced Peripherals

29M Downloads

ME Bridge getItem() does not trigger error upon disconnection

estafeit opened this issue · 7 comments

commented

Describe

It's me again, sorry !

All is in title. If using getItem() with a missing cable, getItem() return is empty but it triggers no error. Same beahviour if item is absent in the network. We need to be able to figure the difference between the two !

ie. I'm tring to craft items only if network don't contains more than a given amount. If I cut the cable by mistake, my rig will keep crafting items without limit, thinking there is none in network.

For now one can do a listItems() first to check if inventory is empty, but that's not good, performance-wise

EDIT: On second thought, listItems() should return an error too ^^

Steps to reproduce

Use getItem() on a disconnected ME bridge

Multiplayer?

No

Version

1.19.2-0.7.27r (Latest 1.19.2)

Minecraft, Forge and maybe other related mods versions

mc 1.19.2, atm 8

Screenshots or Videos

No response

Crashlog/log

No response

commented
bridge = peripheral.find("meBridge")

result, err = bridge.listItems()

if err then
  print("oh no, something isn't right.", err)
end

OK I should have known about isConnected, but I'm positive this does return err == nil and result = {} in my case. Same goes for getItem().

commented

Could you test that? That should not be the case if the bridge is not connected

commented

You can check with isConnected that the bridge is connected and the grid is available

And every method will return an error if it's not connected.

bridge = peripheral.find("meBridge")

result, err = bridge.listItems()

if err then
  print("oh no, something isn't right.", err)
end

This would print the message with a NOT_CONNECTED returned by the bridge

https://github.com/SirEndii/AdvancedPeripherals/blob/63139d1dc010ae4a7af141d185ce7cc64156e443/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java#L132-L134

commented
commented

I assume isConnected only returns false if nothing is connected
But I'll improve that!

commented

I made a simple program to check this :

local bridge = peripheral.find("meBridge")
if (not bridge) then
	print("Can't connect to ME Bridge !")
	return
else
	print("Connected to ME Bridge !")
end

local isConnected = bridge.isConnected()
print("isConnected ? : " .. textutils.serialize(isConnected))

local result, err = bridge.listItems()
print("result:" .. textutils.serialize(result) .. " error: " .. textutils.serialize(err))

. I ran it in two cases. Here are the setups :

  • Totally disconnected (and never connected)
    2023-04-22_01 55 39
  • Connected then disconnected (program run after the disconnection)
    2023-04-22_02 03 39

and in both cases i get this :
2023-04-22_02 04 09

commented

Also my original program is up and running well right now, i'm in no hurry for a fix myself ;)