eliteSchwein / mooncord

Moonraker discord Bot
MIT License
132 stars 24 forks source link

Fix bug with /listfiles #222

Closed geoffreywwang closed 2 years ago

geoffreywwang commented 2 years ago

There is a bug with /listfiles command that causes issues in printers with low number of print files resulting in the /listfiles command to hang/crash. The log file outputs:

[error] [2022-01-15T04:04:20.261Z] TypeError: Cannot read properties of undefined (reading 'path')
      TypeError: Cannot read properties of undefined (reading 'path')
            at /home/pi/mooncord/dist/index.js:15:280399
            at String.replace (<anonymous>)
            at parsePageData (/home/pi/mooncord/dist/index.js:15:280301)
            at PageHelper.getEntries (/home/pi/mooncord/dist/index.js:15:325937)
            at PageHelper.getPage (/home/pi/mooncord/dist/index.js:15:325659)
            at FileListCommand.execute (/home/pi/mooncord/dist/index.js:15:341033)
            at processTicksAndRejections (node:internal/process/task_queues:96:5)

Existing code doesn't seem to account for situations where entities don't fill up the last page. On top of this, it seems to also miscalculate the number of total pages.

This pull request should handle those situations.