PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
5.08k stars 921 forks source link

Missing null check in digging.js #305

Closed Darker closed 3 years ago

Darker commented 9 years ago

I get this unhandled error at random:

C:\Users\Jakub\node_modules\mineflayer\lib\plugins\digging.js:76
          location: bot.targetDigBlock.position,
                                      ^
TypeError: Cannot read property 'position' of null
    at finishDigging [as _onTimeout] (C:\Users\Jakub\node_modules\mineflayer\lib\plugins\digging.js:76:39)
    at Timer.listOnTimeout (timers.js:110:15)
rom1504 commented 9 years ago

Weird, that shouldn't happen. What did you try to do to get that error ?

Darker commented 9 years ago

As I was saying, it happens randomly while the bot is digging. I did not manage to find some correlation with anything more specific.

Darker commented 9 years ago

Ok one case when it happens is when the bot is teleported while digging. The most common situation is when it dies.

rom1504 commented 9 years ago

I can't reproduce that error in these situation. I'm trying on a vanilla server. On what server did you have that error ?

rom1504 commented 9 years ago

Can't reproduce. If this happens again or you can provide a minimal example when it happens, reopen ;)

deathcap commented 8 years ago

I just hit this too (bot.targetDigBlock null in finishDigging https://github.com/PrismarineJS/mineflayer/blob/master/lib/plugins/digging.js#L72) while testing voxel-clientmc, though I don't have a reproducible test case yet either, appears to be related to failed digs in restricted areas and/or multiple simultaneously (race condition?)

rom1504 commented 8 years ago

I can't see how that could happens. finishDigging is only called by the waitTimeout timeout, that timeout is started in the beginning of bot.dig at a place where bot.targetDigBlock is certainly not-null (just after block.position is called). Before setting bot.targetDigBlock to null the timeout is always cancelled.

Not sure what I'm missing. Some weird behavior of js ?

theoparis commented 3 years ago

I am having the same issue, it says cannot read property position of null (digging.js). I am using the pathfinder plugin but it digs and then crashes.

/run/media/theoparis/TheoData/Essentials/Projects/Programming/untitled/node_modules/.pnpm/mineflayer@2.37.1/node_modules/mineflayer/lib/plugins/digging.js:41
        location: bot.targetDigBlock.position,
                                     ^

TypeError: Cannot read property 'position' of null
theoparis commented 3 years ago

It also seems to happen after it dies.

TheDudeFromCI commented 3 years ago

Oh, this was the issue that I was seeing when I was having what I thought was the callback issue mentioned in #1492. Apparently, it was this, not the callback.

UhMarco commented 3 years ago

Forgive me if I'm wrong - I've never contributed before, but would it be a bad idea to just try, except then pass this?

TheDudeFromCI commented 3 years ago

@UhMarco Probably not try-except here, but try to handle in a more graceful way. Find out what's causing it and try to avoid that situation entirely. If it's caused by dying or teleporting while mining, then those events should properly cancel active tasks properly.

TheDudeFromCI commented 3 years ago

I have seen this issue a significant number of times in the past week from new users in the Discord. I suspect a regression bug?

rom1504 commented 3 years ago

What is "this issue" exactly ? From above messages there are no clear error messages, no code and no context.

rom1504 commented 3 years ago

I think we should close this and re-open better issues

rom1504 commented 3 years ago

The only thing we can do here is add that null check so errors would be more explicit

TheDudeFromCI commented 3 years ago

@rom1504 The error code is:

...\node_modules\mineflayer\lib\plugins\digging.js:76
          location: bot.targetDigBlock.position,
                                      ^
TypeError: Cannot read property 'position' of null
    at finishDigging [as _onTimeout] (...\node_modules\mineflayer\lib\plugins\digging.js:76:39)
    at Timer.listOnTimeout (timers.js:110:15)

This error seems to be thrown at random under seemingly unknown circumstances while the bot attempts to break a block. Usually by the pathfinder plugin or the collect block plugin. It's most likely triggered when the bot dies/teleports while in the middle of digging or tries to break a block and the server rejects it for some reason. (Ghost blocks?)

We can reopen the issue with a cleaner context if you'd like, but it's not known what code causes it. It a seemly random effect, but suddenly very common.

rom1504 commented 3 years ago

We can first add more null checks in that code and emit errors if the null cannot be handled at this point. It should clarify things

On Tue, Dec 22, 2020, 12:23 TheDudeFromCI notifications@github.com wrote:

@rom1504 https://github.com/rom1504 The error code is:

...\node_modules\mineflayer\lib\plugins\digging.js:76 location: bot.targetDigBlock.position, ^ TypeError: Cannot read property 'position' of null at finishDigging [as _onTimeout] (...\node_modules\mineflayer\lib\plugins\digging.js:76:39) at Timer.listOnTimeout (timers.js:110:15)

This error seems to be thrown at random under seemingly unknown circumstances while the bot attempts to break a block. Usually by the pathfinder plugin or the collect block plugin. It's most likely triggered when the bot dies/teleports while in the middle of digging or tries to break a block and the server rejects it for some reason. (Ghost blocks?)

We can reopen the issue with a cleaner context if you'd like, but it's not known what code causes it. It a seemly random effect, but suddenly very common.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/305#issuecomment-749492217, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437TLUJCRKZCZQYXE7RTSWB6SHANCNFSM4BKZOWAQ .