BetterBags icon indicating copy to clipboard operation
BetterBags copied to clipboard

grid.lua:242: invalid order function for sorting

Open rwygand opened this issue 1 year ago • 3 comments

Addon Version

v0.3.18

World of Warcraft Version

Retail

Describe the bug

5x BetterBags/frames/grid.lua:242: invalid order function for sorting [string "=[C]"]: in function sort' [string "@BetterBags/frames/grid.lua"]:242: in function Sort' [string "@BetterBags/views/gridview.lua"]:371: in function Render' [string "@BetterBags/frames/bag.lua"]:316: in function Draw' [string "@BetterBags/core/init.lua"]:290: in function cb' [string "@BetterBags/core/events.lua"]:49: in function <BetterBags/core/events.lua:47> [string "=[C]"]: ? [string "@Masque/Libs/CallbackHandler-1.0-8/CallbackHandler-1.0.lua"]:19: in function <...que/Libs/CallbackHandler-1.0/CallbackHandler-1.0.lua:15> [string "@Masque/Libs/CallbackHandler-1.0-8/CallbackHandler-1.0.lua"]:54: in function SendMessage' [string "@BetterBags/core/events.lua"]:206: in function `SendMessage' [string "@BetterBags/core/events.lua"]:224: in function <BetterBags/core/events.lua:223>

Locals: (*temporary) =

{ 1 =
{ } 2 =
{ } 3 =
{ } 4 =
{ } 5 =
{ } 6 =
{ } 7 =
{ } 8 =
{ } 9 =
{ } 10 =
{ } 11 =
{ } 12 =
{ } 13 =
{ } 14 =
{ } 15 =
{ } 16 =
{ } 17 =
{ } 18 =
{ } 19 =
{ } 20 =
{ } 21 =
{ } 22 =
{ } 23 =
{ } 24 =
{ } 25 =
{ } 26 =
{ } 27 =
{ } 28 =
{ } 29 =
{ } 30 =
{ } 31 =
{ } 32 =
{ } 33 =
{ } 34 =
{ } 35 =
{ } 36 =
{ } 37 =
{ } } (*temporary) =
{ view = 2 headerDisabled = false title = Button { } fillWidth = false maxItemsPerRow = 7 content =
{ } frame = Frame { } } (*temporary) =
{ view = 2 headerDisabled = false title = Button { } fillWidth = false maxItemsPerRow = 7 content =
{ } frame = Frame { } }

Steps to reproduce

I just opened my bags after running Grim Batol 10 and started getting this error.

rwygand avatar Oct 29 '24 05:10 rwygand

This is happening again after getting out of Comp Stomp. Multiple reloads and the problem persists, and I'm unable to see anyitem in my bags.

image

rwygand avatar Nov 23 '24 04:11 rwygand

I continue to see this happen inconsistently. The only BetterBags plugin I use is BetterBags: Gear First. That does affect sorting, so it could be related.

rwygand avatar Mar 10 '25 20:03 rwygand

I've been getting this and also use Gear Frist, so going to try disabling and see if it resolves

rfein-hearst avatar Apr 30 '25 21:04 rfein-hearst

Fixed

This issue was caused by external addons modifying BetterBags' saved variables, resulting in invalid sort type values being retrieved from the database. When GetSectionSortFunction() encountered an unknown sort type, it would pass an invalid (nil or non-function) value to grid:Sort(), causing the "invalid order function for sorting" error.

Changes Made

  1. util/sort.lua:55 - Fixed the fallback logic to return a proper alphabetical sort function directly instead of making a recursive call with incorrect parameters

  2. frames/grid.lua:242 - Added defensive guard to validate the sort function parameter:

    • Checks if fn is actually a function using type(fn) ~= "function"
    • Falls back to a no-op comparison function if invalid
    • Prevents crashes regardless of what external addons do to saved variables
  3. Documented pattern - Added new defensive programming pattern to .roo/rules/patterns.md for handling external addon interference

The fix ensures BetterBags gracefully handles corrupted saved variables by validating function parameters and providing safe defaults, preventing crashes when external addons modify the addon's data.

Cidan avatar Oct 05 '25 20:10 Cidan