microsoft / microsoft/AdaptiveCards

[.NET][Templating] Whenever a null value is evaluated, a warning should be raised

Open
#4,646 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Templating Platform-.NET Request
Dominant language
C#
Stars
2k
Forks
595
Avg merge
1d 19h
Merged PRs (30d)
1

Description

Platform

  • .NET WPF

Version of SDK

Templating nuget

Details

With the fix of #4574 an error was unearthed where expressions that are evaluated to null will provide a confusing user and developer experience as they won't know what may be failing.

For example, this test should fail or raise a warning but it doesn't

[TestMethod]
        public void TestExceptionHandling()
        {
            // ${LineItem} doesn't exist in the data context provided
            string jsonTemplate = @"{
            ""type"": ""AdaptiveCard"",
            ""body"": [
              {
                ""type"": ""Container"",
                ""items"": [
                  {
                    ""$data"": ""${LineItem}"",
                    ""type"": ""TextBlock"",
                    ""text"": ""${Milage}""
                  }
                ]
              }
            ]
        }";

            string jsonData = @"{
              ""LineItems"": [
                {
                    ""Milage"": 10
                },
                {
                    ""Milage"": 0
                }
              ]
            }";

            AdaptiveCardTemplate transformer = new AdaptiveCardTemplate(jsonTemplate);
            var context = new EvaluationContext
            {
                Root = jsonData
            };

            try
            {
                string cardJson = transformer.Expand(context);
                Assert.Fail("There should be an exception");
            }
            catch (AdaptiveTemplateException e)
            {
                Assert.AreEqual(@"'${LineItem}' at line, '8' is malformed for '$data : ' pair", e.Message);
            }
            catch
            {
                Assert.Fail();
                throw;
            }
        }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AdaptiveCardTemplate.Expand and the TestExceptionHandling example in the issue, then trace how expressions such as ${LineItem} are evaluated against EvaluationContext. Add coverage for a missing or null evaluation and verify that the resulting behavior reports the problem rather than silently continuing.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.