Skip to content

Fix(ui): Avoid ERROR macro conflict in iconcodes#48

Open
QuellaZhang wants to merge 1 commit into
musescore:mainfrom
QuellaZhang:main
Open

Fix(ui): Avoid ERROR macro conflict in iconcodes#48
QuellaZhang wants to merge 1 commit into
musescore:mainfrom
QuellaZhang:main

Conversation

@QuellaZhang
Copy link
Copy Markdown

Rename ERROR enum value to ERROR_ICON and update the related #undef guard to prevent macro name collisions on some platforms or third-party headers.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR renames the ERROR enum enumerator to ERROR_ICON in the muse::ui::IconCode::Code enum within framework/ui/view/iconcodes.h. The change includes updating the preprocessor macro guard from #ifdef ERROR to #ifdef ERROR_ICON to undefine the conflicting macro name. The underlying icon code value 0xF3D0 remains unchanged.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description explains the change (renaming ERROR to ERROR_ICON) and its purpose (preventing macro collisions), but does not follow the repository's template with required sections. Add issue reference (Resolves: #NNNNN), confirm CLA signature, and use the full template structure for clarity and consistency with repository standards.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: renaming an ERROR enum value to avoid macro conflicts in iconcodes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@framework/ui/view/iconcodes.h`:
- Around line 34-36: The preprocessor guard for ERROR_ICON is unnecessary
because ERROR_ICON is not a platform macro; remove the `#ifdef` ERROR_ICON /
`#undef` ERROR_ICON / `#endif` block and instead either leave no undef for
ERROR_ICON or, if the intent was to avoid colliding with platform ERROR, restore
the original `#undef` ERROR (not ERROR_ICON) before defining the enum entries;
update any enum rename references (e.g., ERROR_ICON vs ERROR) so the enum uses
the intended identifier (such as ERROR_ICON) and ensure WARNING, INFO, QUESTION
handling remains unchanged.
- Line 343: The QML enum named in code is now ERROR_ICON (not ERROR), so update
all places returning or referencing IconCode.ERROR — specifically in the
StandardDialogPanel.qml function standardIcon(type) (and any other QML/JS
callers) change IconCode.ERROR to IconCode.ERROR_ICON; search for IconCode.ERROR
usages and replace them with IconCode.ERROR_ICON to prevent QML enum
lookup/compile failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0d51e0a6-f903-4d82-9d0e-5e519d16b9b4

📥 Commits

Reviewing files that changed from the base of the PR and between b7c2a97 and 6e9e255.

📒 Files selected for processing (1)
  • framework/ui/view/iconcodes.h

Comment on lines +34 to 36
#ifdef ERROR_ICON
#undef ERROR_ICON
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | 💤 Low value

The ERROR_ICON guard is unnecessary.

Unlike ERROR, WARNING, INFO, and QUESTION, the name ERROR_ICON is not a macro defined by platform headers (e.g., Windows). This guard serves no protective purpose and can be safely removed. Alternatively, if downstream headers still require ERROR to be cleared, the original #undef ERROR should be retained alongside the enum rename.

🧹 Suggested removal
-#ifdef ERROR_ICON
-#undef ERROR_ICON
-#endif
📝 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
#ifdef ERROR_ICON
#undef ERROR_ICON
#endif
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/ui/view/iconcodes.h` around lines 34 - 36, The preprocessor guard
for ERROR_ICON is unnecessary because ERROR_ICON is not a platform macro; remove
the `#ifdef` ERROR_ICON / `#undef` ERROR_ICON / `#endif` block and instead either
leave no undef for ERROR_ICON or, if the intent was to avoid colliding with
platform ERROR, restore the original `#undef` ERROR (not ERROR_ICON) before
defining the enum entries; update any enum rename references (e.g., ERROR_ICON
vs ERROR) so the enum uses the intended identifier (such as ERROR_ICON) and
ensure WARNING, INFO, QUESTION handling remains unchanged.

WARNING = 0xF3CE,
INFO = 0xF3CF,
ERROR = 0xF3D0,
ERROR_ICON = 0xF3D0,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Search for usages of the old Code::ERROR enum value that need updating.

# Search for explicit Code::ERROR or IconCode::ERROR references
rg -n --type=cpp --type=qml -e 'Code::ERROR\b' -e 'IconCode::ERROR\b' -g '!iconcodes.h'

# Also check for QML usages
rg -n -e 'IconCode\.ERROR\b' --type-add 'qml:*.qml' --type=qml

Repository: musescore/muse_framework

Length of output: 182


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== iconcodes.h enum definitions around ERROR ==="
rg -n --type=cpp "enum class Code|ERROR_ICON|\\bERROR\\b" framework/ui/view/iconcodes.h
echo "--- snippet near ERROR_ICON ---"
python3 - <<'PY'
import re
path="framework/ui/view/iconcodes.h"
start=300; end=420
with open(path,'r',encoding='utf-8',errors='ignore') as f:
    lines=f.readlines()
for i in range(start-1,end):
    if 1<=i+1<=len(lines):
        print(f"{i+1}: {lines[i].rstrip()}")
PY

echo
echo "=== Remaining usages of old names (excluding iconcodes.h) ==="
rg -n --type=cpp --type=qml -e 'Code::ERROR\b' -e 'IconCode::ERROR\b' -g '!iconcodes.h' .
rg -n -e 'IconCode\.ERROR\b' --type-add 'qml:*.qml' --type=qml .

echo
echo "=== Usages of new names (ERROR_ICON) ==="
rg -n --type=cpp --type=qml -e 'ERROR_ICON\b' -g '!iconcodes.h' .
rg -n -e 'IconCode\.ERROR_ICON\b' --type-add 'qml:*.qml' --type=qml . || true

echo
echo "=== Specific QML mapping location found earlier ==="
rg -n "case \"ERROR\"" -S framework/interactive/qml/Muse/Interactive/StandardDialogPanel.qml
sed -n '60,105p' framework/interactive/qml/Muse/Interactive/StandardDialogPanel.qml

Repository: musescore/muse_framework

Length of output: 3236


🏁 Script executed:

#!/bin/bash
set -u

echo "=== iconcodes.h: presence of ERROR_ICON ==="
rg -n --type=cpp "ERROR_ICON\\b" framework/ui/view/iconcodes.h

echo
echo "=== QML: remaining IconCode.ERROR references ==="
rg -n --type=qml "IconCode\\.ERROR\\b" . || true

echo
echo "=== QML: case \"ERROR\" mapping ==="
rg -n 'case[[:space:]]+"ERROR"' -S --type=qml framework/interactive/qml/Muse/Interactive/StandardDialogPanel.qml || true
sed -n '70,100p' framework/interactive/qml/Muse/Interactive/StandardDialogPanel.qml

echo
echo "=== Usages of ERROR_ICON ==="
rg -n --type=cpp --type=qml "\\bERROR_ICON\\b" . -g '!iconcodes.h' || true
rg -n --type=qml "IconCode\\.ERROR_ICON\\b" . || true

Repository: musescore/muse_framework

Length of output: 1306


🏁 Script executed:

#!/bin/bash
set -u

echo "=== iconcodes.h: occurrences of ERROR not followed by _ (to catch potential aliases) ==="
rg -n --type=cpp -S "ERROR(?!_)" framework/ui/view/iconcodes.h || true

echo
echo "=== iconcodes.h: lines mentioning ERROR_ICON specifically ==="
rg -n --type=cpp "ERROR_ICON" framework/ui/view/iconcodes.h

echo
echo "=== iconcodes.h: top-of-file preprocessor context around ERROR_ICON ==="
sed -n '1,120p' framework/ui/view/iconcodes.h

echo
echo "=== iconcodes.h: QML exposure (Q_ENUM / Q_NAMESPACE / etc) near the enum ==="
# show a wider window around the enum declaration and any QML macros
sed -n '40,120p' framework/ui/view/iconcodes.h
sed -n '320,380p' framework/ui/view/iconcodes.h

echo
echo "=== sanity: any 'ERROR' enum value entries in iconcodes.h (comma form) ==="
rg -n --type=cpp "ERROR\\s*=" framework/ui/view/iconcodes.h || true
rg -n --type=cpp "ERROR\\s*," framework/ui/view/iconcodes.h || true

Repository: musescore/muse_framework

Length of output: 7021


Breaking API change: remaining IconCode.ERROR usage needs updating
framework/ui/view/iconcodes.h defines ERROR_ICON (no ERROR enum value), but framework/interactive/qml/Muse/Interactive/StandardDialogPanel.qml:84 still returns IconCode.ERROR in standardIcon(type) when type === "ERROR"—update it to IconCode.ERROR_ICON to avoid QML enum lookup/compile failures.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/ui/view/iconcodes.h` at line 343, The QML enum named in code is now
ERROR_ICON (not ERROR), so update all places returning or referencing
IconCode.ERROR — specifically in the StandardDialogPanel.qml function
standardIcon(type) (and any other QML/JS callers) change IconCode.ERROR to
IconCode.ERROR_ICON; search for IconCode.ERROR usages and replace them with
IconCode.ERROR_ICON to prevent QML enum lookup/compile failures.

@igorkorsukov
Copy link
Copy Markdown
Member

igorkorsukov commented May 22, 2026

Could you please provide the compiler error log?
Maybe we can find a way to fix this differently?

We know that Windows headers contain #define ERROR
That's why the compilation error occurs.
But that's precisely why was added

#ifdef ERROR
#undef ERROR
#endif

Isn't that enough?

This enumerator is used in MuseScoreStudio and Audacity. Therefore, if we change it, we need to change the code in both projects... It also needs to look consistent, as the rabbit pointed out...

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.

2 participants