iOfficeAI/OfficeCLI · error · ArgumentException

{fullKey}: expected boolean (true/false/1/0/yes/no/on/off),

Error message

{fullKey}: expected boolean (true/false/1/0/yes/no/on/off), got '{value}'.

What it means

Thrown by ValidateTrendlineOptionValue (ChartHelper.Setter.cs:4509) when a trendline display-flag sub-key — dispRsqr, rsquared, r2, displayrsquared, dispeq, equation, displayequation — receives a value that is not one of the eight literal boolean tokens true/false/1/0/yes/no/on/off. This is a parse-only pre-validation pass (fuzz-TL01/TL02) so the bad value is rejected even when the chart has no trendline element to apply it to yet. The validator's accepted set is deliberately narrow and exact-matches after Trim+ToLowerInvariant.

Source

Thrown at src/officecli/Core/Chart/ChartHelper.Setter.cs:4509

    private static void ValidateTrendlineOptionValue(string subKey, string value, string fullKey)
    {
        switch (subKey)
        {
            case "name" or "label":
                break; // any string is valid
            case "forward" or "forecastforward"
                or "backward" or "forecastbackward"
                or "intercept":
                ParseHelpers.SafeParseDouble(value, fullKey);
                break;
            case "order" or "period":
                ParseHelpers.SafeParseInt(value, fullKey);
                break;
            case "disprsqr" or "rsquared" or "r2" or "displayrsquared"
                or "dispeq" or "equation" or "displayequation":
                var v = (value ?? "").Trim().ToLowerInvariant();
                if (v is not ("true" or "false" or "1" or "0" or "yes" or "no" or "on" or "off"))
                    throw new ArgumentException(
                        $"{fullKey}: expected boolean (true/false/1/0/yes/no/on/off), got '{value}'.");
                break;
        }
    }

    // R8-3: previously the dotted show* / top-level show* setters only flipped
    // existing <c:dLbls> containers. On a chart whose data labels had been
    // cleared (datalabels=none, or new charts emitted without dLbls), the
    // Descendants<DataLabels> enumeration returned nothing and the operation
    // succeeded silently with no XML change. Caller saw success=true and an
    // unchanged chart — surprise round-trip behaviour. Enable-by-show*
    // semantics expect us to materialise a minimal container when one is
    // missing; collect (and seed if needed) the DataLabels for each chartType
    // in the PlotArea.
    private static bool EnsureDataLabelsForShowToggle(
        C.Chart chart, string key, List<string> unsupported, out List<C.DataLabels> dataLabels)
    {
        dataLabels = new List<C.DataLabels>();

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Pass one of the accepted tokens literally: true, false, 1, 0, yes, no, on, off.
  2. Trim and ToLowerInvariant the value client-side before setting the property so stray casing/whitespace cannot trip the exact match.
  3. Map any upstream boolean to 'true'/'false' before forwarding it as the option value.

Example fix

// before
series1.trendline.displayRSquared=show
// after
series1.trendline.displayRSquared=true
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> TrendlineBoolTokens = new(StringComparer.OrdinalIgnoreCase)
{ "true","false","1","0","yes","no","on","off" };
static string NormalizeTrendlineBool(string v)
{
    var t = (v ?? "").Trim().ToLowerInvariant();
    return TrendlineBoolTokens.Contains(t) ? t : throw new ArgumentException($"expected boolean token, got '{v}'");
}

Type guard

static bool IsTrendlineBoolToken(string v) =>
    TrendlineBoolTokens.Contains((v ?? "").Trim().ToLowerInvariant());

Try / catch

try { /* set chart series1.trendline.displayRSquared=... */ }
catch (ArgumentException ex) when (ex.Message.Contains("expected boolean"))
{ /* surface to user: list accepted tokens */ }

Prevention

When it happens

Trigger: Setting series1.trendline.displayRSquared=show, chart.trendline.displayEquation=enabled, or any dispRsqr/dispEq alias to a value outside {true,false,1,0,yes,no,on,off}, e.g. 'Y', 'on ' (trailing space untrimmed by caller), '2', 'enable'.

Common situations: UI code passing 'show'/'hide' or 'enabled'/'disabled' without mapping to the canonical tokens; booleans copied from localized data; stray whitespace or mixed casing that the caller did not normalize.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/7d7a8d35461998d0. Report an issue: GitHub.