Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Create a list of error/warning codes #986

Closed

Description

@mateoatr

Related to #769

By adhering to the format used by MSBuild to output warnings and errors to the standard output (which give us for free the capacity to surface these warnings/errors inside IDEs such as Visual Studio), we are required to define (at least) the following items:

Origin: tool name or filename, more broadly what is producing the warning/error. I think that if we are to make the warnings actionable by the user, we should show the filename where the warning is coming from together with the line and column.

Code: list of error/warning codes specific to the illinker, these have to be prefixed with a string that identifies the linker. There's an ongoing discussion related to this in the Roslyn repo.

Some examples of the MSBuild message format together with the complete list of its parameters can be found here.

Activity

  1. added this to the .NET5.0 milestone on Mar 11, 2020
  2. marek-safar commented on Mar 11, 2020

    @marek-safar
    Contributor

    I suspect we'll have to create 2 code groups (similar to what csc does with CSxxxx and CAxxxx) to cover cases where linker produces error/warning and linker analyzer produces error/warning

  3. mateoatr commented on Apr 3, 2020

    @mateoatr
    ContributorAuthor

    Trying to move forward with this, here's a table with all different messages that we currently log via LogMessage inside the linker, together with a proposed set of category, subcategory and error/warning code to use for these.

    Text Proposed category Proposed subcategory Proposed code Location in codebase
    Could not resolve '{assemblyName}' assembly dependency Warning Unresolved dependency 6001 MarkStep
    Could not resolve '{typeName}' type dependency Warning Unresolved dependency 6002 MarkStep
    Could not resolve dependency member '{member}' declared in type '{td.FullName}' Error Unresolved dependency 0001 MarkStep
    Could not resolve type '{fullname}' for substitution Error 0002 BodySubstituterStep
    Could not match assembly '{name.FullName}' for substitution Error 0003 BodySubstituterStep
    Could not find method '{signature}' for substitution Error 0004 BodySubstituterStep
    Could not find field '{name}' for substitution. Error 0005 BodySubstituterStep
    Invalid value for '{signature}' stub Error 0006 BodySubstituterStep
    Unknown body modification '{action}' for '{signature}' Error 0007 BodySubstituterStep
    Substituted field '{name}' needs to be static field. Error 0008 BodySubstituterStep
    Missing 'value' attribute for field '{field}'. Error 0009 BodySubstituterStep
    Invalid value for '{field}': '{value}'. Error 0010 BodySubstituterStep
    Unreachable IL reduction is not supported for method '{Body.Method.FullName}' Warning 6003 RemoveUnreachableBlockStep
    Reduced '{reducer.InstructionsReplaced}' instructions in conditional branches for [{method.DeclaringType.Module.Assembly.Name}] method {method.FullName} Diagnostic RemoveUnreachableBlockStep
    Output action: {action,8} assembly: {assembly} Diagnostic OutputStep
  4. sbomer commented on Apr 4, 2020

    @sbomer
    Member

    Regarding #968 and #1064:

    This API allows arbitrary messages/subcategories with arbitrary error codes

    LogMessage (CreateDiagnosticMessage ("something happened"));
    LogMessage (CreateWarningMessage ("Assembly.dll", 1234, "Unresolved assembly"))
    LogMessage (CreateErrorMessage ("specific something", 5678, "Invalid something", origin: someOrigin))
    

    and also seems a bit verbose.

    Should we consider instead exposing methods that give a single source of truth for warnings and errors? Something like:

    LogDiagnostic ("something happened"))
    LogWarning (Warnings.UnresolvedAssembly, "Assembly.dll"))
    LogError (Errors.InvalidSomething, "specific something", origin: someOrigin))
    

    where the enums map error IDs to format strings?

    There might need to be an extensibility mechanism for custom steps, but I would hesitate to expose the full string/id/subcategory combination as public API. With the current API it will be difficult to ensure that the error codes and messages are used consistently.

  5. marek-safar commented on Apr 6, 2020

    @marek-safar
    Contributor

    I think the proposed table is very restrictive. Most (if not all) errors are actually not even warnings but normal messages

    Here is my "rules table"

    Severity Logic
    Error The end-user must take action and there is a clear message about what that should be.
    Warning Severe issue which will most likely cause unintended behaviour.
    Normal Progress like messages.
    Diagnostics Information which will help us to diagnose unexpected behaviour or confirm correct behaviour.

    where the enums map error IDs to format strings?

    I'm not sure this will help actually. Is it better to duplicate the strings instead of the numbers? I think we can for custom steps expose different APIs for Error and Warnings.

    Something like

    public static MessageContainer CreateErrorMessage (string text, Type customStepType, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null)
    

    It would use always the same code but we would somehow encode the step type name into the message.

  6. sbomer commented on Apr 6, 2020

    @sbomer
    Member

    Is it better to duplicate the strings instead of the numbers?

    Sorry, I wasn't clear enough. My concern wasn't with the duplication of IDs, but with the potential for IDs to be used with unrelated strings.

    If we we have messages that are sometimes warnings and sometimes errors, we could avoid duplication by using a single enum for both warnings and errors. What I meant to say was that this unifies the ID with the warning/error string. If we need to share error strings this could also look like:

    LogWarning (DiagnosticIDs.UnresolvedAssembly, "Assembly.dll")
    LogError (DiagnosticIDs.InvalidSomething, "specific something")
    

    I think we should use an API where each ID maps to a specific format string, not one that can combine IDs/strings arbitrarily.

  7. mateoatr commented on Apr 6, 2020

    @mateoatr
    ContributorAuthor

    We will be using IDs only for errors and warnings. I think it's a good idea to have an enum where we put a list of all the possible e/w the linker could log, and then map these to a string format. For e/w coming from custom steps, we could simply provide a specific ID where a plain string needs to be passed.

  8. marek-safar commented on Apr 6, 2020

    @marek-safar
    Contributor

    I think it's a good idea to have an enum where we put a list of all the possible e/w the linker could log

    Why do you think this is a good idea?

    For e/w coming from custom steps, we could simply provide a specific ID where a plain string needs to be passed.

    Right so we would hide the id on the API but perhaps we can use custom step name instead of MessageOrigin which will probably not be used by custom steps

  9. mateoatr commented on Apr 7, 2020

    @mateoatr
    ContributorAuthor

    Why do you think this is a good idea?

    I think that having an enum and mapping it to a string format could help us have a cleaner API while avoiding any potential mistakes on the text/ID pairs. It can also be a good way to keep track of all the different messages that we know the illinker can log and the correspondence between these and the IDs.

    perhaps we can use custom step name instead of MessageOrigin which will probably not be used by custom steps

    Yes, I think that for custom steps we can receive its type as you proposed and use it as a kind of 'origin', and then provide a special ID for this scenario.

  10. marek-safar commented on Apr 7, 2020

    @marek-safar
    Contributor

    I think that having an enum and mapping it to a string format could help us have a cleaner API while avoiding any potential mistakes on the text/ID pairs.

    I actually see that as bad practice. The goal of the error codes is for end-users and support to easily find them, understand them or refer to them at any point in time. What I think we should do instead is to use numbers in code (no enums to keep the code readable) and have table (documentation) with all codes for all versions at https://github.com/mono/linker/blob/master/src/linker/ErrorCodes.md

    potential mistakes on the text/ID pairs

    I don't think this is worth "optimizing" for it. We keep maintaining a page with all codes and descriptions instead.

  11. sbomer commented on Apr 7, 2020

    @sbomer
    Member

    How does using an enum as a definitive list of warnings/errors make it any harder to build documentation for that list? It seems to me that putting them in one place would make it easier if anything.

  12. vitek-karas commented on Apr 7, 2020

    @vitek-karas
    Member

    I can appreciate the desire to see the actual number in the code where it originates from. So what if the enum is the exact string something like:

    enum Codes
    {
        IL6001 = 6001, // What is this for
        IL6002 = 6002, // What is this for second
        ...
    }

    I like the enum as it's easy to make sure when adding a new code that it's unique. And the code in this case would naturally act as developers documentation.

    As for custom steps - I'm not sure we should restrict custom steps to exactly one code. The code acts as two things:

    • A short and specific way to identify the type of issue when looking it up in docs, discussing in issues, with support and so on.
    • A way to identify a type of issue for which to modify behavior - in case of warnings, to be able to disable the warning selectively.

    If we restrict the custom steps to single code they have potentially issues like this:

    • If they need both errors and warnings, those would end up with the same code. While not unheard of (C# sometimes does this as well), it's relatively a bad practice I think
    • If they have a set of warnings for which it would be beneficial to disable them without disabling the rest of warnings from that custom step - there would be no way to do that - basically either all or nothing approach.

    On the other hand, if we allow more than one, it creates a problem with assigning ranges. But we will have the problem of assigning numbers to custom steps even if they have just one anyway.

  13. marek-safar commented on Apr 8, 2020

    @marek-safar
    Contributor

    I like the enum as it's easy to make sure when adding a new code that it's unique. And the code in this case would naturally act as developers documentation.

    I'd much rather not to have this documented in the code but in proper documentation .md file. If we go with the additional enum type people will probably update just that and not the documentation page so for that reason I'd rather avoid duplicating the information.

    If they need both errors and warnings, those would end up with the same code.

    We'd give unique number to custom warnings and custom errors (basically 2 different codes).

    If they have a set of warnings for which it would be beneficial to disable them without disabling the rest of warnings from that custom step

    Yep but is that bad thing? You can disable a warning in specific code region only.

    On the other hand, if we allow more than one, it creates a problem with assigning ranges.

    Thinking about it we should probably enable custom ids in specific ranges and have an additional page with codes documentation for custom steps. The risk of theoretically overlapping codes is not worth compromising on usability.

  14. vitek-karas commented on Apr 8, 2020

    @vitek-karas
    Member

    You can disable a warning in specific code region only.

    I don't understand this. C# can disable warnings locally in the source code, but linker won't have that ability. All warnings will be "global".

    I'd much rather not to have this documented in the code but in proper documentation .md file.

    OK - It's just a matter of style I guess. I'm perfectly fine if we agree on having a doc instead (and make sure it's up to date in code reviews).

  15. marek-safar commented on Apr 8, 2020

    @marek-safar
    Contributor

    All warnings will be "global".

    Good point, that's another reason to go with range of codes for custom steps

  16. mateoatr commented on Apr 10, 2020

    @mateoatr
    ContributorAuthor

    Ok, so we'll keep things as they currently are and create a MD file to track all the errors and warnings that could possibly be logged by the linker. I'll start by changing all current instances of LogMessage in places where we should report a warning to use the new MessageContainer and I'll create a markdown file to keep track of its IDs and messages. For the IDs I'll just start with 2001 for the warnings. We can later decide which range are we to reserve for custom steps.

  17. marek-safar commented on Apr 10, 2020

    @marek-safar
    Contributor

    We can later decide which range are we to reserve for custom steps.

    Let's do it now, the code using the custom codes will be written shortly.

    My suggestion is to go with the following ranges

    Core Linker
    Errors: 1000 - 1999
    Warnings: 2000 - 3999

    Custom Steps
    Errors: 5000 - 6999
    Warnings: 7000 - 9999

    with a recommendation for SDK with custom steps to reserve a range of 99 codes

  18. mateoatr commented on Apr 10, 2020

    @mateoatr
    ContributorAuthor

    Is there any reason to not use values in 4xxx?

  19. vitek-karas commented on Apr 10, 2020

    @vitek-karas
    Member

    I would actually leave out 4xxx and 9xxx - just to leave us some wiggle room for the future. 7K should be enough codes for everyone (famous last words ;-))

  20. marek-safar commented on Apr 11, 2020

    @marek-safar
    Contributor

    Yep, the intention was to have some flexibility for the future

  21. vitek-karas commented on Jun 8, 2020

    @vitek-karas
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions