@@ -962,12 +962,16 @@ function Start-UnityEditor {
962
962
963
963
$process = Start-Process @setProcessArgs
964
964
if ( $Wait ) {
965
- if ( $process.ExitCode -ne 0 ) {
966
- if ( $LogFile -and (Test-Path $LogFile - Type Leaf) ) {
967
- Write-Verbose " Writing $LogFile to Information stream Tagged as 'Logs'"
968
- Get-Content $LogFile | ForEach-Object { Write-Information - MessageData $_ - Tags ' Logs' }
969
- }
965
+ if ( $LogFile -and (Test-Path $LogFile - Type Leaf) ) {
966
+ # Note that Unity sometimes returns a success ExitCode despite the presence of errors, but we want
967
+ # to make sure that we flag such errors.
968
+ Write-UnityErrors $LogFile
969
+
970
+ Write-Verbose " Writing $LogFile to Information stream Tagged as 'Logs'"
971
+ Get-Content $LogFile | ForEach-Object { Write-Information - MessageData $_ - Tags ' Logs' }
972
+ }
970
973
974
+ if ( $process.ExitCode -ne 0 ) {
971
975
Write-Error " Unity quit with non-zero exit code: $ ( $process.ExitCode ) "
972
976
}
973
977
}
@@ -977,6 +981,46 @@ function Start-UnityEditor {
977
981
}
978
982
}
979
983
984
+ # Open the specified Unity log file and write any errors found in the file to the error stream.
985
+ function Write-UnityErrors {
986
+ param ([string ] $LogFileName )
987
+ Write-Verbose " Checking $LogFileName for errors"
988
+ $errors = Get-Content $LogFileName | Where-Object { Get-IsUnityError $_ }
989
+ if ( $errors.Count -gt 0 ) {
990
+ $errors = $errors | select - uniq # Unity prints out errors as they occur and also in a summary list. We only want to see each unique error once.
991
+ $errorMessage = $errors -join " `r`n "
992
+ $errorMessage = " Errors were found in $LogFileName `:`r`n $errorMessage "
993
+ Write-Error $errorMessage
994
+ }
995
+ }
996
+
997
+ function Get-IsUnityError {
998
+ param ([string ] $LogLine )
999
+
1000
+ # Detect Unity License error, for example:
1001
+ # BatchMode: Unity has not been activated with a valid License. Could be a new activation or renewal...
1002
+ if ( $LogLine -match ' Unity has not been activated with a valid License' ) {
1003
+ return $true
1004
+ }
1005
+
1006
+ # Detect that the method specified by -ExecuteMethod doesn't exist, for example:
1007
+ # executeMethod method 'Invoke' in class 'Build' could not be found.
1008
+ if ( $LogLine -match ' executeMethod method .* could not be found' ) {
1009
+ return $true
1010
+ }
1011
+
1012
+ # Detect compilation error, for example:
1013
+ # Assets/Errors.cs(7,9): error CS0103: The name `NonexistentFunction' does not exist in the current context
1014
+ if ( $LogLine -match ' \.cs\(\d+,\d+\): error ' ) {
1015
+ return $true
1016
+ }
1017
+
1018
+ # In the future, additional kinds of errors that can be found in Unity logs could be added here:
1019
+ # ...
1020
+
1021
+ return $false
1022
+ }
1023
+
980
1024
function ConvertTo-DateTime {
981
1025
param ([string ] $Text )
982
1026
0 commit comments