Enabling extended error logging in Office Add-ins (to see full statements on error object) [closed]
Asked Answered
L

1

8

I'm developing an add-in and I'm encountering an error.
A bunch of stuff is printed to the console, and some of it is:

What does that mean? How do I enable that setting?

Loaf answered 21/6, 2018 at 22:52 Comment(0)
M
13

Great question!

Imagine you have code like this:

async function run() {
  await Excel.run(async (context) => {
    const range = context.workbook.getSelectedRange();
    range.getRow(1000).format.fill.color = "yellow";
    await context.sync();
  });
}

And imagine that your selection is only a small range, such that getRow(1000) will cause an exception.

If you run this today, you'll get some information:

Error screenshot

But note that you don't get the full set of statements, only the "surrounding" ones (which, if you had a bunch of code, might not be enough). And also, that some of the information is "..."-ed out for you.

Now, stick the following line somewhere above your code:

OfficeExtension.config.extendedErrorLogging = true;

Once you have that, you'll get full error logging (which is great for debugging, but please don't do this in production apps -- you don't want to pay the performance cost, and more importantly, you don't want to log and store sensitive data, which might well be present in the log of the full statements (e.g., a 2D values array containing customer info...)

Full statements, after enabling "OfficeExtension.config.extendedErrorLogging"

From the Office d.ts file on DefinitelyTyped:

/** Configuration */
var config: {
  /**
   * Determines whether to log additional error information upon failure.
   *
   * When this property is set to true, the error object will include a "debugInfo.fullStatements" property that lists all statements in the batch request, including all statements that precede and follow the point of failure.
   *
   * Setting this property to true will negatively impact performance and will log all statements in the batch request, including any statements that may contain potentially-sensitive data.
   * It is recommended that you only set this property to true during debugging and that you never log the value of error.debugInfo.fullStatements to an external database or analytics service.
   */
   extendedErrorLogging: boolean;
};
Murmuration answered 22/6, 2018 at 2:44 Comment(6)
Thanks! I successfully solved the problem by commenting out office-js-related lines and see if the problem keeps occurring, which eventually leads to the few lines that do matter, and I found the problematic lines. Turns out that a sheet name can't have certain characters in it.Loaf
Well, turns out that it's not necessarily the characters that are problematic - but the total amount of characters.Loaf
Glad it helped! Yes, I believe both are true — if you try it in the UI, you will see that Excel both doesn’t allow certain characters, AND had a length limit (31 or 32 characters, IIRC).Murmuration
In my Word add-in I get: OfficeExtension is not defined when I do soTussle
@NathanB, it should work, provided that you're making this call sometime after "Office.onReady()" has fired.Murmuration
That being said, I have left the Office Extensibility team some time ago. If you're having issues, I'd recommend posting a new question so that it shows up on the radar for current members of the Office Extensibility team...Murmuration

© 2022 - 2024 — McMap. All rights reserved.