Skip to content

fix: Compile fails fast on asmdef and asmref import errors#1225

Merged
hatayama merged 7 commits into
v3-betafrom
feature/hatayama/fix-asmdef-console-errors
May 27, 2026
Merged

fix: Compile fails fast on asmdef and asmref import errors#1225
hatayama merged 7 commits into
v3-betafrom
feature/hatayama/fix-asmdef-console-errors

Conversation

@hatayama

Copy link
Copy Markdown
Owner

Summary

  • uloop compile now fails quickly when current Unity Console contains Assembly Definition or Assembly Reference import errors.
  • The error response points to the affected .asmdef or .asmref file instead of waiting for compilation that Unity never starts.

User Impact

  • Before this change, import errors in assembly definition files could leave uloop compile waiting indefinitely because Unity did not enter script compilation.
  • After this change, users get a structured failure with the current Console error and can fix the asset immediately. Stale Console entries from already fixed or deleted assets do not keep blocking compile.

Changes

  • Check current Unity Console entries after asset refresh and again when compilation fails to start.
  • Confirm asmdef and asmref Console errors against current asset state, including malformed JSON, duplicate references, duplicate assembly names, missing asmref targets, folder conflicts, and GUID/name duplicate references.
  • Keep the existing duplicate asmdef fallback for compile-start timeout and add focused EditMode coverage.

Verification

  • Packages/src/Cli~/dist/darwin-arm64/uloop compile --project-path "$(git rev-parse --show-toplevel)"
  • Packages/src/Cli~/dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type exact --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.AssemblyDefinitionConsoleErrorValidationServiceTests"
  • ~/.codex/skills/codex-review/scripts/codex-review --parallel-tests '<compile && focused EditMode tests>' v3-beta
  • Manual repros for malformed asmdef, duplicate asmdef references, GUID/name duplicate references, malformed asmref, asmref folder conflict, and asset paths containing parentheses.

hatayama added 5 commits May 27, 2026 21:09
Use the same current Unity Console source as get-logs to fail compile when .asmdef or .asmref import errors are present. Run the detection only after AssetDatabase.Refresh so fixed assembly definition errors are not blocked by stale pre-refresh Console entries.
Avoid treating arbitrary stale Console errors that merely mention .asmdef or .asmref paths as active import failures. Keep compile blocking focused on Unity Assembly Definition and Assembly Reference importer messages.
Prevent retained Unity Console entries from blocking compile after the referenced asmdef or asmref asset has been fixed or removed. Treat generic asmref parse messages as current failures only when the asset still validates as an import problem.
Count asmref files alongside asmdef files when validating Unity's folder-conflict Console errors so compile fails fast instead of waiting for a start timeout.
Handle malformed asmdef JSON, duplicate references that mix assembly names and GUIDs, and valid Unity asset paths containing parentheses so current Console import errors do not fall through to compile start timeouts.
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hatayama, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 2 minutes and 23 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b082379-c6ef-4c36-8870-06aa4b0630ef

📥 Commits

Reviewing files that changed from the base of the PR and between bac009a and 8f00870.

📒 Files selected for processing (3)
  • Assets/Tests/Editor/AssemblyDefinitionConsoleErrorValidationServiceTests.cs
  • Packages/src/Editor/FirstPartyTools/Compile/AssemblyDefinitionConsoleErrorValidationService.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs
📝 Walkthrough

Walkthrough

Adds an editor-side validator that parses Unity Console import errors for .asmdef/.asmref paths, verifies asset/importer state to determine if errors are current, and formats compile-failure messages. CompileController invokes this validator after asset refresh and during compile startup to abort with prepared failures when current import errors are detected. Tests cover parsing and filtering.

Changes

Assembly Definition Error Validation and Compile Integration

Layer / File(s) Summary
Validation service, models, and tests
Packages/src/Editor/FirstPartyTools/Compile/AssemblyDefinitionConsoleErrorValidationService.cs, Assets/Tests/Editor/AssemblyDefinitionConsoleErrorValidationServiceTests.cs
Adds AssemblyDefinitionConsoleErrorValidationService, plus immutable AssemblyDefinitionConsoleError and AssemblyDefinitionConsoleErrorResult models. Service extracts .asmdef/.asmref paths from console entries, de-duplicates issues by (asset, message), verifies currentness via AssetDatabase/AssetImporter checks (JSON parse, required fields, duplicate names/refs, multiple definition files), and formats a capped compile-failure message. Tests validate parsing of asmdef/asmref messages (including parenthesized paths), exclusion of non-error or stale entries, and currentness gating.
CompileController integration and completion refactor
Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs, Packages/src/Editor/FirstPartyTools/Compile/CompilationStateValidationService.cs, Packages/src/Editor/ToolContracts/UnityCliLoopConstants.cs
After AssetDatabase.Refresh and within the pre-compile wait loop, CompileController queries the validation service and, if current errors exist, builds a failed CompileResult and completes/aborts the active compile early. Adds AbortCompileWithResult, central CompleteCompileRequest(CompileResult, bool), CompleteCompileWithoutRequest, UnregisterCompilationEvents, and helpers converting AssemblyDefinitionConsoleErrorResult/errors into CompileResult/CompilerMessage[]. CompilationStateValidationService.ValidateCompilationState() no longer performs the prior asmdef duplicate-name console check. Adds ERROR_MESSAGE_ASSEMBLY_DEFINITION_IMPORT_ERROR constant.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: implementing fast-fail behavior for asmdef and asmref import errors during compilation.
Description check ✅ Passed The description clearly explains the problem, solution, user impact, and verification approach, all directly related to the changeset.
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
  • Commit unit tests in branch feature/hatayama/fix-asmdef-console-errors

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.

Ensure compile controller state and task completion are restored even when completion subscribers throw. This keeps abort and finish paths from leaving stale compile flags or pending tasks behind.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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
`@Packages/src/Editor/FirstPartyTools/Compile/AssemblyDefinitionConsoleErrorValidationService.cs`:
- Around line 223-225: To fix incorrect handling of virtual "Packages/..." asset
paths, update ToAbsolutePath to detect paths starting with "Packages/", call
UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath), and when it
returns a PackageInfo use its resolvedPath to map the virtual package prefix to
the package's actual on-disk path (replace the "Packages/<packageName>" prefix
with package.resolvedPath, then continue with existing normalization). This
ensures callers like HasMultipleAssemblyDefinitionFilesInFolder and
ReadAssetText correctly resolve non-embedded package files via
PackageInfo.resolvedPath instead of assuming they live under
<projectRoot>/Packages/.

In `@Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs`:
- Around line 254-258: Capture the current TaskCompletionSource<CompileResult>
into a local variable, immediately set _currentCompileTask = null, then invoke
OnCompileCompleted?.Invoke(result) and finally call task.SetResult(result); do
this in the current completion path and mirror the same ordering in
CompleteCompileWithoutRequest(...) so that subscribers that start a new compile
inside OnCompileCompleted cannot have their new TaskCompletionSource overwritten
by the old SetResult.
🪄 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: CHILL

Plan: Pro

Run ID: 872713f0-3d72-4d31-b62d-b7779336746b

📥 Commits

Reviewing files that changed from the base of the PR and between f2562a4 and 8470fd2.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/AssemblyDefinitionConsoleErrorValidationServiceTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Compile/AssemblyDefinitionConsoleErrorValidationService.cs.meta is excluded by none and included by none
📒 Files selected for processing (5)
  • Assets/Tests/Editor/AssemblyDefinitionConsoleErrorValidationServiceTests.cs
  • Packages/src/Editor/FirstPartyTools/Compile/AssemblyDefinitionConsoleErrorValidationService.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompilationStateValidationService.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs
  • Packages/src/Editor/ToolContracts/UnityCliLoopConstants.cs
💤 Files with no reviewable changes (1)
  • Packages/src/Editor/FirstPartyTools/Compile/CompilationStateValidationService.cs

Comment thread Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 7 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs Outdated
Resolve review feedback by cleaning compile startup state on pre-request failures, mapping Package Manager asset paths through resolved package locations, and treating only error import log entries as blocking asmdef or asmref import errors.
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.

1 participant