Forum Discussion

Ben-Dev's avatar
Ben-Dev
Helper II
4 years ago
Solved

M Language - Error Records' New Fields (Message.Format & Message.Parameters

Hello,

 

At some point in the not too distant past, error records were expanded from three fields (Reason, Message, Details) to five fields (with the addition of fields Message.Format and Message.Parameters). Can someone from Microsoft detail the exepection for how these fields should be used/work? 

 

A guess is that these fields are provided to support a form of structured logging, for example, by setting Message to something like "Some Message - count: {count}, code: {code}" and then setting Message.Parameters to a list of two items.

 

However, this is just a guess. Official confirmation/details would be most helpful.

 

Thanks!

 

/CC: Ehren 

  • Your guess is correct. 🙂

     

    Here's an example:

    error [
        Message.Format = "Hello #{0}.",
        Message.Parameters = {"world"}
    ]

4 Replies

  • Ehren's avatar
    Ehren
    Microsoft Employee

    Your guess is correct. 🙂

     

    Here's an example:

    error [
        Message.Format = "Hello #{0}.",
        Message.Parameters = {"world"}
    ]
    • Ben-Dev's avatar
      Ben-Dev
      Helper II

      Thanks, Ehren, for the quick reply!

       

      A couple questions:

      • Are the parameters pared with the {something} placeholders in the message positionally? So the first parameter in the list goes with the first placeholder in the message, the second param with the second placeholder, etc.? (Think the answer is "yes.")
      • What is the difference between error fields Message and Message.Format? Error.Record sets them to both be the same value, but I'm guessing they are separate fields because there may be reasons for them to have different values.
      • Is there any way to get the mashup engine to fill in the placeholders when rendering the error out in the UI? For example, "error Error.Record("Some Reason", "Some Message - count: {count}, code: {code}", null, {123, "abc"})" is rendered without giving the user any clue as to the placeholder's values. Should the UI be filling in the placeholders when displaying the error?
      • Ehren's avatar
        Ehren
        Microsoft Employee

        See the example I added above after my initial response.