Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

44 fix missing auction in undercut json #45

Merged
merged 2 commits into from
Nov 24, 2024

Conversation

berickus
Copy link
Collaborator

@berickus berickus commented Nov 22, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new debugging module for enhanced logging and table representation.
    • Updated the addon's interface version, ensuring compatibility with newer versions.
  • Bug Fixes

    • Improved table iteration methods for more robust handling within various functions.
  • Chores

    • Added .DS_Store to the .gitignore file to prevent unnecessary files from being tracked.
    • Cleaned up workflow configuration by removing commented sections for clarity.

@berickus berickus linked an issue Nov 22, 2024 that may be closed by this pull request
@berickus berickus requested a review from cohenaj194 November 22, 2024 13:09
Copy link

coderabbitai bot commented Nov 22, 2024

Walkthrough

The pull request introduces several changes across multiple files. Notably, it updates the GitHub Actions workflow to include the WAGO_API_TOKEN environment variable for the release job. The .gitignore file is modified to include .DS_Store. A new Lua module, Debug, is added for enhanced logging and debugging functionality. The SaddlebagExchangeWoW.toc file is updated to reflect a new interface version and includes the newly created Core/Debug.lua. Additionally, the main.lua file undergoes significant changes, including updates to table iteration methods and the logging mechanism.

Changes

File Change Summary
.github/workflows/release.yml Added WAGO_API_TOKEN to release job; removed commented-out sections.
.gitignore Added .DS_Store to ignored files; .vscode/ entry remains unchanged.
Core/Debug.lua Introduced new module with Debug.Log, Debug.TableToString, and private function GetDebugChatFrame.
Libs/AceConsole-3.0/AceConsole-3.0.xml Added newline at the end of the file.
SaddlebagExchangeWoW.toc Updated interface versions to 110005; added Core\Debug.lua; repositioned main.lua.
main.lua Updated iteration methods from ipairs to pairs; replaced print statements with Saddlebag.Debug.Log.

Possibly related issues

  • Fix missing auction in undercut json: The changes in main.lua related to logging and table handling may address issues with missing auction data in JSON outputs.

Possibly related PRs

Poem

In the code where bunnies hop,
A token added, we won't stop!
Debugging now with style and grace,
Our logs will shine, a happy place.
With every change, we leap and cheer,
Saddlebag's better, oh so dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (9)
.github/workflows/release.yml (1)

36-36: Add newline at end of file.

The file is missing a newline character at the end, which is required by POSIX standards.

Apply this diff to fix the issue:

 WAGO_API_TOKEN: ${{ secrets.WAGO_API_TOKEN }}
+
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

Core/Debug.lua (4)

10-11: Fix the line break in the GetChatWindowInfo assignment

The assignment of GetChatWindowInfo spans two lines unnecessarily.

-local GetChatWindowInfo = 
-GetChatWindowInfo
+local GetChatWindowInfo = GetChatWindowInfo

18-23: Add function documentation and consider debug levels

The logging function would benefit from:

  1. Documentation explaining its purpose and parameters
  2. Support for different debug levels (e.g., INFO, WARN, ERROR)
+--- Logs a debug message to the SBDebug chat frame if it exists
+-- @param msg (string) The message to log
+-- @param ... (any) Optional format arguments for the message
 function Debug.Log(msg, ...)
     local chatFrame = private.GetDebugChatFrame()
     if chatFrame then
         SB:Printf(chatFrame, msg, ...)
     end
 end

Consider adding debug levels:

Debug.Level = {
    INFO = 1,
    WARN = 2,
    ERROR = 3
}

function Debug.Log(level, msg, ...)
    local chatFrame = private.GetDebugChatFrame()
    if chatFrame and level >= (SB.debugLevel or Debug.Level.INFO) then
        SB:Printf(chatFrame, msg, ...)
    end
end

60-72: Improve chat frame lookup efficiency and robustness

Consider these improvements:

  1. Cache the chat frame reference
  2. Use NUM_CHAT_WINDOWS constant instead of hardcoded 10
  3. Add error logging when debug frame is not found
+local debugChatFrame
 function private.GetDebugChatFrame() -- private
+    if debugChatFrame then
+        return debugChatFrame
+    end
     local tab = -1
-    for i = 1, 10 do
+    for i = 1, NUM_CHAT_WINDOWS do
         if GetChatWindowInfo(i)=="SBDebug" then
             tab = i
             break
         end
     end

     if(tab ~= -1) then
-        return _G["ChatFrame"..tab]
+        debugChatFrame = _G["ChatFrame"..tab]
+        return debugChatFrame
+    else
+        -- Log only once when debug frame is not found
+        if not private.warnedNoDebugFrame then
+            print("SaddlebagExchange: Debug chat frame 'SBDebug' not found")
+            private.warnedNoDebugFrame = true
+        end
     end
 end

1-72: Consider architectural improvements for debugging infrastructure

To enhance the debugging capabilities, consider:

  1. Add configuration options in the addon's settings panel to:
    • Enable/disable debug logging
    • Set debug level threshold
    • Configure max depth/entries for table serialization
  2. Integrate with WoW's built-in debugging tools:
    • Support for /dump command
    • Integration with addon development tools like DevTools_Dump
  3. Add support for log categories to filter different types of debug messages
main.lua (4)

67-67: Consider keeping ipairs for sequential command arguments

The change from ipairs to pairs is unnecessary here as command arguments are always sequential and order-dependent. Using ipairs would better represent the sequential nature of command processing.

-    for _, arg in pairs(args) do
+    for _, arg in ipairs(args) do

118-121: Improve string formatting in Debug.Log calls

While the addition of debug logging is good, the string concatenation could be improved using string formatting for better performance and readability.

-    Saddlebag.Debug.Log("Setting up multiSelect with auctions "..Saddlebag:tableLength(auctions))
-    for _, item in pairs(auctions) do
-        local itemName, _, _, _, _, _, _, _ = GetItemInfo(item["itemKey"]["itemID"])
-        Saddlebag.Debug.Log("Adding item "..itemName)
+    Saddlebag.Debug.Log(string.format("Setting up multiSelect with %d auctions", Saddlebag:tableLength(auctions)))
+    for _, item in pairs(auctions) do
+        local itemName, _, _, _, _, _, _, _ = GetItemInfo(item["itemKey"]["itemID"])
+        Saddlebag.Debug.Log(string.format("Adding item %s", itemName))

128-128: Improve string formatting in auction counting logs

The debug logging additions are helpful for tracking auction processing, but the string concatenation should use string formatting for better performance and readability.

-    Saddlebag.Debug.Log("Found "..Saddlebag:tableLength(ownedAuctions).." auctions.")
-    Saddlebag.Debug.Log("Found "..tostring(active_auctions).." active auctions.")
-    Saddlebag.Debug.Log("Found "..Saddlebag:tableLength(clean_ownedAuctions).." unique auctions.")
+    Saddlebag.Debug.Log(string.format("Found %d auctions", Saddlebag:tableLength(ownedAuctions)))
+    Saddlebag.Debug.Log(string.format("Found %d active auctions", active_auctions))
+    Saddlebag.Debug.Log(string.format("Found %d unique auctions", Saddlebag:tableLength(clean_ownedAuctions)))

Also applies to: 137-137, 160-160


Line range hint 1-489: Consider improving code modularity and button management

The codebase could benefit from the following architectural improvements:

  1. Create a ButtonManager class to handle button creation and management
  2. Implement a centralized logging system with configurable levels
  3. Consider using a proper UI framework or library for consistent button behavior

This would improve maintainability and reduce code duplication.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ad01b41 and 28ce707.

📒 Files selected for processing (6)
  • .github/workflows/release.yml (1 hunks)
  • .gitignore (1 hunks)
  • Core/Debug.lua (1 hunks)
  • Libs/AceConsole-3.0/AceConsole-3.0.xml (1 hunks)
  • SaddlebagExchangeWoW.toc (2 hunks)
  • main.lua (13 hunks)
✅ Files skipped from review due to trivial changes (2)
  • .gitignore
  • Libs/AceConsole-3.0/AceConsole-3.0.xml
🧰 Additional context used
🪛 yamllint (1.29.0-1)
.github/workflows/release.yml

[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (6)
SaddlebagExchangeWoW.toc (2)

15-17: LGTM! Good file organization

The placement of Core\Debug.lua before main.lua is correct, ensuring the Debug module is loaded before it's used. This follows good addon development practices for dependency management.


1-2: Verify WoW interface version compatibility

The interface version has been updated from 10.2.7 (100207) to 11.0.5 (110005). Please ensure this matches the current WoW retail version to avoid compatibility issues.

Run the following to check other addon files in the repository for consistent interface versions:

✅ Verification successful

Interface version 110005 (11.0.5) is correct for current WoW retail

Based on the repository's recent changes in CHANGELOG.md which mentions "updated interface version" and the fact that World of Warcraft is currently on patch 11.0.5 (Dragonflight), the interface version update to 110005 is correct and matches the current retail version.

The older interface version (80100) found in LibRealmInfo.toc is from a library dependency and doesn't affect the addon's compatibility, as libraries often maintain backward compatibility with older versions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any inconsistent interface versions across addon files
rg -i "## Interface:" 
rg -i "## X-Min-Interface:"

Length of output: 206


Script:

#!/bin/bash
# Let's check the git history to understand the interface version changes
git log -p --no-merges -G "## Interface:" -- SaddlebagExchangeWoW.toc | head -n 50

Length of output: 0


Script:

#!/bin/bash
# Let's also check if there are any README or documentation files that might mention WoW version compatibility
fd -e md -e txt | xargs rg -i "wow|version|interface|compatibility" 

Length of output: 3533


Script:

#!/bin/bash
# Check if there are any version-related constants or configurations in Lua files
rg -i "version|interface" --type lua

Length of output: 21220

.github/workflows/release.yml (1)

36-36: LGTM! Verify WAGO_API_TOKEN secret configuration.

The addition of WAGO_API_TOKEN is appropriate for publishing to Wago.io. The token is correctly referenced from GitHub secrets.

Run this script to verify the secret is configured:

🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

main.lua (3)

20-20: LGTM: Appropriate use of pairs iterator

The change from ipairs to pairs is correct here as we need to search through all key-value pairs, not just sequential indices.


30-30: LGTM: Appropriate use of pairs for index retrieval

The change from ipairs to pairs is correct as we need to find the actual key/index of the value, which might not be sequential.


202-202: LGTM: Clear and helpful error message

The error message clearly explains what went wrong and how to fix it.

Comment on lines +25 to +57
function Debug.TableToString ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
SB.Debug.Log(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
SB.Debug.Log(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
SB.Debug.Log(indent..string.rep(" ",string.len(pos)+6).."}")
elseif (type(val)=="string") then
SB.Debug.Log(indent.."["..pos..'] => "'..val..'"')
else
SB.Debug.Log(indent.."["..pos.."] => "..tostring(val))
end
end
else
SB.Debug.Log(indent..tostring(t))
end
end
end
if (type(t)=="table") then
SB.Debug.Log(tostring(t).." {")
sub_print_r(t," ")
SB.Debug.Log("}")
else
sub_print_r(t," ")
end
SB.Debug.Log("")
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add safety measures to table serialization

The current implementation has potential issues:

  1. No maximum depth limit could cause stack overflow with deeply nested tables
  2. No size limit could cause performance issues with large tables
  3. Multiple Debug.Log calls are inefficient; consider building a string first

Consider implementing these safety measures:

-function Debug.TableToString ( t )
+function Debug.TableToString(t, maxDepth, maxEntries)
+    maxDepth = maxDepth or 10
+    maxEntries = maxEntries or 100
     local print_r_cache={}
+    local result = {}
+    local entryCount = 0
-    local function sub_print_r(t,indent)
+    local function sub_print_r(t, indent, depth)
+        if depth > maxDepth then
+            table.insert(result, indent.."*max depth reached*")
+            return
+        end
+        if entryCount > maxEntries then
+            table.insert(result, indent.."*max entries reached*")
+            return
+        end
         if (print_r_cache[tostring(t)]) then
-            SB.Debug.Log(indent.."*"..tostring(t))
+            table.insert(result, indent.."*"..tostring(t))
         else
             print_r_cache[tostring(t)]=true
             if (type(t)=="table") then
                 for pos,val in pairs(t) do
+                    entryCount = entryCount + 1
+                    if entryCount > maxEntries then break end
                     if (type(val)=="table") then
-                        SB.Debug.Log(indent.."["..pos.."] => "..tostring(t).." {")
-                        sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
-                        SB.Debug.Log(indent..string.rep(" ",string.len(pos)+6).."}")
+                        table.insert(result, indent.."["..pos.."] => "..tostring(t).." {")
+                        sub_print_r(val, indent..string.rep(" ",string.len(pos)+8), depth + 1)
+                        table.insert(result, indent..string.rep(" ",string.len(pos)+6).."}")
                     else
-                        SB.Debug.Log(indent.."["..pos.."] => "..tostring(val))
+                        table.insert(result, indent.."["..pos.."] => "..tostring(val))
                     end
                 end
             end
         end
     end
-    sub_print_r(t,"  ")
+    sub_print_r(t, "  ", 1)
+    return table.concat(result, "\n")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function Debug.TableToString ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
SB.Debug.Log(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
SB.Debug.Log(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
SB.Debug.Log(indent..string.rep(" ",string.len(pos)+6).."}")
elseif (type(val)=="string") then
SB.Debug.Log(indent.."["..pos..'] => "'..val..'"')
else
SB.Debug.Log(indent.."["..pos.."] => "..tostring(val))
end
end
else
SB.Debug.Log(indent..tostring(t))
end
end
end
if (type(t)=="table") then
SB.Debug.Log(tostring(t).." {")
sub_print_r(t," ")
SB.Debug.Log("}")
else
sub_print_r(t," ")
end
SB.Debug.Log("")
end
function Debug.TableToString(t, maxDepth, maxEntries)
maxDepth = maxDepth or 10
maxEntries = maxEntries or 100
local print_r_cache={}
local result = {}
local entryCount = 0
local function sub_print_r(t, indent, depth)
if depth > maxDepth then
table.insert(result, indent.."*max depth reached*")
return
end
if entryCount > maxEntries then
table.insert(result, indent.."*max entries reached*")
return
end
if (print_r_cache[tostring(t)]) then
table.insert(result, indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
entryCount = entryCount + 1
if entryCount > maxEntries then break end
if (type(val)=="table") then
table.insert(result, indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val, indent..string.rep(" ",string.len(pos)+8), depth + 1)
table.insert(result, indent..string.rep(" ",string.len(pos)+6).."}")
else
table.insert(result, indent.."["..pos.."] => "..tostring(val))
end
end
end
end
end
sub_print_r(t, " ", 1)
return table.concat(result, "\n")
end

@@ -367,11 +366,11 @@ function Saddlebag:addonButton()
addonButton:RegisterForDrag("LeftButton")
addonButton:SetScript("OnDragStart", function(self, button)
self:StartMoving()
-- print("OnDragStart", button)
Saddlebag.Debug.Log("OnDragStart", button)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider refactoring duplicate button drag logging

The drag event logging is duplicated across three buttons. Consider creating a helper function to reduce code duplication.

+function Saddlebag:SetupButtonDrag(button)
+    button:SetScript("OnDragStart", function(self, buttonArg)
+        self:StartMoving()
+        Saddlebag.Debug.Log("OnDragStart", buttonArg)
+    end)
+    button:SetScript("OnDragStop", function(self)
+        self:StopMovingOrSizing()
+        Saddlebag.Debug.Log("OnDragStop")
+    end)
+end

 function Saddlebag:addonButton()
     local addonButton = CreateFrame("Button", "MyButton", UIParent, "UIPanelButtonTemplate")
     -- ... other setup code ...
-    addonButton:SetScript("OnDragStart", function(self, button)
-        self:StartMoving()
-        Saddlebag.Debug.Log("OnDragStart", button)
-    end)
-    addonButton:SetScript("OnDragStop", function(self)
-        self:StopMovingOrSizing()
-        Saddlebag.Debug.Log("OnDragStop")
-    end)
+    Saddlebag:SetupButtonDrag(addonButton)
     -- ... rest of the function ...
 end

Also applies to: 373-373, 402-402, 406-406, 435-435, 439-439

@berickus
Copy link
Collaborator Author

@cohenaj194 now to debug you can create a new chat window called SBDebug. All logs will be posted there when it exists.

@berickus berickus merged commit 86a44bc into main Nov 24, 2024
1 check passed
@berickus berickus deleted the 44-fix-missing-auction-in-undercut-json branch November 24, 2024 08:52
@cohenaj194
Copy link
Contributor

@cohenaj194 now to debug you can create a new chat window called SBDebug. All logs will be posted there when it exists.

Sweet sounds good. Can you put a few screenshots in the CurseForge page and git eiki?

@berickus
Copy link
Collaborator Author

yes I will update all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix missing auction in undercut json
2 participants