Skip to content

Commit c492a49

Browse files
committed
detect Unity compiler errors in the log file and output them to error output
1 parent 0704262 commit c492a49

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ function Start-UnityEditor {
964964
if ( $Wait ) {
965965
if ( $process.ExitCode -ne 0 ) {
966966
if ( $LogFile -and (Test-Path $LogFile -Type Leaf) ) {
967+
Write-UnityErrors $LogFile
967968
Write-Verbose "Writing $LogFile to Information stream Tagged as 'Logs'"
968969
Get-Content $LogFile | ForEach-Object { Write-Information -MessageData $_ -Tags 'Logs' }
969970
}
@@ -977,6 +978,32 @@ function Start-UnityEditor {
977978
}
978979
}
979980

981+
# Open the specified Unity log file and write any errors found in the file to the error stream.
982+
function Write-UnityErrors {
983+
param([string] $LogFileName)
984+
$errors = Get-Content $LogFileName | Where-Object { Get-IsUnityError $_ }
985+
if ( $errors.Count -gt 0 ) {
986+
$errorMessage = $errors -join "`r`n"
987+
$errorMessage = "Errors were found in $LogFileName`:`r`n$errorMessage"
988+
Write-Error $errorMessage
989+
}
990+
}
991+
992+
function Get-IsUnityError {
993+
param([string] $LogLine)
994+
995+
# Detect compilation error, for example:
996+
# Assets/Errors.cs(7,9): error CS0103: The name `NonexistentFunction' does not exist in the current context
997+
if ( $LogLine -match '\.cs\(\d+,\d+\): error ' ) {
998+
return $true
999+
}
1000+
1001+
# In the future, additional kinds of errors that can be found in Unity logs could be added here:
1002+
# ...
1003+
1004+
return $false
1005+
}
1006+
9801007
function ConvertTo-DateTime {
9811008
param([string] $Text)
9821009

0 commit comments

Comments
 (0)