Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Execute code even with compiler errors

Discussion in 'Testing & Automation' started by liortal, Oct 4, 2020.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,505
    We are using TeamCity for automatically building our game + running tests.
    Analyzing errors in our automated pipieline is very important for us - if an error occurs we want to be able to easily understand what went wrong.

    I would like to add some code to monitor Unity's log (for errors / exceptions) and store it somewhere or report it in a different format (TeamCity has an internal message format that is used for displaying stuff in its UI).

    The problem is - in case a developer pushes code with compiler errors - will my editor code still execute? (this code registers itself on log messages, kinda like this):
    Code (CSharp):
    1. public static class UnityLogListener
    2. {
    3.     [InitializeOnLoadMethod]
    4.     private static void Init()
    5.     {
    6.         Application.logMessageReceived += OnLogMessageReceived;
    7.     }
    8.  
    9.     private static void OnLogMessageReceived(string condition, string stackTrace, LogType type)
    10.     {
    11.         if (type == LogType.Error || type == LogType.Exception)
    12.         {
    13.             // TODO: send to TeamCityLogger
    14.         }
    15.     }
    16. }
    Is there any way to ensure this code will execute, even if compiler errors are present ?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,505
  3. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,485
    I'm not sure that compilation pipeline results get loaded if there are compile errors, even for the assemblies that did compile successfully. You might need to store this 'always-executable' code in a precompiled assembly in the project.
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,505
    I put the code in assembly-csharp-editor-firstpass, isn't it enough? i assumed it will be compiled and loaded before other assemblies and so any errors in them would allow me to peek into that
     
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,485
    As I said:

    Test it and see.
     
  6. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,505
    Tested - looks a bit inconclusive - sometimes the changes were not reflected immediately.
    Even precompiled didn't help (i need to enforce this gets loaded - but i think with compilation errors it may not be loaded to memory).

    I think i'll still with Assembly-CSharp-Editor-Firstpass as its the closest thing to what i want (load early on, also in case of error)
     
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,485
    I'm surprised to hear that precompiled didn't help - I believe that's the mechanism that Cloud Build uses.
     
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,505
    Precompiled DLL - but where do you drop it? i only looked at the "firstpass" approach to make sure the thing is loaded into memory before anything else
     
  9. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,485
    I don't think it should matter whereabouts in the project it is - the firstpass stuff only affects compilation order, not assembly load order.
     
unityunity