OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
690 stars 95 forks source link

ElevatedPermissionNeededForMethod error sometimes breaks event based logic in Outlook Desktop (old) #5124

Open bogdanst24 opened 1 week ago

bogdanst24 commented 1 week ago

Provide required information needed to triage your issue

Your Environment

Expected behavior

Event-based add-ins are to work as expected, or a suggestive error will be thrown if errors are being made in code.

Current behavior

Event-based actions such as OnNewMessageCompose or OnMessageRecipientsChanged, in Outlook Desktop (the old one), sometimes fail with Unable to get property 'l_ElevatedPermissionNeededForMethod_Text' of undefined or null reference. This issue is seen in our error logs for 3497 times in the past 7 days, 70 different customers. It is not always happening and cannot be reproduced by us or by the customers at request.

Steps to reproduce

Cannot reproduce.

Provide additional details

  1. The only other report around this is here https://github.com/OfficeDev/office-js/issues/2204 and it concluded with the usage of promises being the problem. We are indeed using promises, but at the same time the code is transpiled to ES16 and it works correctly in the majority of cases. There is even documentation about how to do it and I don't remember seeing anything about not using them anywhere. If this would be the case, we would need an official confirmation as it would basically require us to rewrite the entire project.

Example of usage:

export function getRecipients() {
  return new Promise<Office.EmailAddressDetails[]>((resolve, reject) => {
    const { mailbox } = Office.context;

    if (!mailbox.item) {
      reject(new Error('Unable to get recipients: No mailbox item'));
      return;
    }

    mailbox.item.to.getAsync({}, asyncResultCallback(resolve, reject));
  });
}

export function asyncResultCallback<ReturnType>(
  resolve: (value: ReturnType) => void,
  reject: (reason?: unknown) => void,
): (asyncResult: Office.AsyncResult<ReturnType>) => void {
  const { AsyncResultStatus } = Office;

  return ({ error, status, value, diagnostics }) => {
    if (status !== AsyncResultStatus.Succeeded) {
      reject({
        ...error,
        errorOrigin: 'OfficeJS',
        diagnostics: diagnostics as unknown,
      });
      return;
    }

    resolve(value);
  };
}
  1. Not sure if related, but we are assigning a random GUID to all items and storing it as a custom property. Then, that id is passed in the error object. (We're doing this as in Outlook Dekstop the message ID is not available before the item is saved and we needed a method to correlate the different errors). For most of these exceptions, there is no ID. Could this be caused by a CustomPropertiesService issue? Obviously, we're first checking for an existing one.
  2. We have some reports from a customer experiencing this exception that the Web Add-in works for a few hours until at some point it crashes and then disappears from the Ribbon. Also, the events are not triggered anymore (as expected). Restarting Outlook solves the issue until it occurs again. Could this be related or help identity the cause?

Useful logs

Examples of exceptions:

{"message":"Unable to get property 'l_ElevatedPermissionNeededForMethod_Text' of undefined or null reference","description":"Unable to get property 'l_ElevatedPermissionNeededForMethod_Text' of undefined or null reference","number":-2146823281,"stack":"TypeError: Unable to get property 'l_ElevatedPermissionNeededForMethod_Text' of undefined or null reference\n   at H (Unknown script code:26:16539)\n   at B (Unknown script code:26:16710)\n   at Anonymous function (Unknown script code:26:48768)\n   at Anonymous function (Unknown script code:1:45225)\n   at B (Unknown script code:10:38607)\n   at D (Unknown script code:1:45091)\n   at Jt (Unknown script code:1:51487)\n   at Anonymous function (Unknown script code:7:16682)\n   at Generator.prototype.next (native code)\n   at ot (Unknown script code:7:15145)"}

Redacted the user name

{"stack":"TypeError: Cannot read properties of undefined (reading 'l_ElevatedPermissionNeededForMethod_Text')\n    at H (C:\\Program Files\\Microsoft Office\\root\\Office16\\olk-launchevent-host.win32.bundle:26:16547)\n    at B (C:\\Program Files\\Microsoft Office\\root\\Office16\\olk-launchevent-host.win32.bundle:26:16718)\n    at Object.<anonymous> (C:\\Program Files\\Microsoft Office\\root\\Office16\\olk-launchevent-host.win32.bundle:26:48768)\n    at C:\\Users\\***\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{98C45364-3071-46B3-BD6B-422B61272356}\\Jte1SMcezEX_QO77B5Wo1g==\\Javascript\\5801732f-85b5-4ecb-9bd5-8e928c9088ca_1.0.0.14_en-US\\bundle.js:1:45254\n    at new Promise (<anonymous>)\n    at D (C:\\Users\\***\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{98C45364-3071-46B3-BD6B-422B61272356}\\Jte1SMcezEX_QO77B5Wo1g==\\Javascript\\5801732f-85b5-4ecb-9bd5-8e928c9088ca_1.0.0.14_en-US\\bundle.js:1:45091)\n    at Jt (C:\\Users\\***\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{98C45364-3071-46B3-BD6B-422B61272356}\\Jte1SMcezEX_QO77B5Wo1g==\\Javascript\\5801732f-85b5-4ecb-9bd5-8e928c9088ca_1.0.0.14_en-US\\bundle.js:1:51494)\n    at C:\\Users\\***\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{98C45364-3071-46B3-BD6B-422B61272356}\\Jte1SMcezEX_QO77B5Wo1g==\\Javascript\\5801732f-85b5-4ecb-9bd5-8e928c9088ca_1.0.0.14_en-US\\bundle.js:7:16694\n    at Generator.next (<anonymous>)\n    at ot (C:\\Users\\***\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{98C45364-3071-46B3-BD6B-422B61272356}\\Jte1SMcezEX_QO77B5Wo1g==\\Javascript\\5801732f-85b5-4ecb-9bd5-8e928c9088ca_1.0.0.14_en-US\\bundle.js:7:15149)","message":"Cannot read properties of undefined (reading 'l_ElevatedPermissionNeededForMethod_Text')"}

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

pepso commented 6 days ago

We have a few hundreds of these per week for appointment fetching, and they seem to coalesce around HR users. We have assumed these are due to some "restricted" or "protected" configuration of their inboxes and/or appointment's attachments.

However, we don't see the behavior that the add-in stops working/removed from ribbon, but this can be because the add-in sandbox is recreated between the appointment being opened/created.

It would be great to have an explanation what is the real cause of these so we know how to communicate this to our clients.