Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access data provider from another extension if your extension starts first #439

Closed
tjcouch-sil opened this issue Sep 25, 2023 · 1 comment · Fixed by #537
Closed
Assignees
Labels
bug Something isn't working

Comments

@tjcouch-sil
Copy link
Member

As an extension developer, I want to be able to access data providers from extensions I want to use without having weird timing issues that have nothing to do with my code or the other extension's code.


When Roopa wrote an extension ("Extension B") that uses a data provider registered by another extension ("Extension A"), she couldn't get the data provider in Extension B because it was activating before Extension A. We have lots of code that tries to mitigate timing issues (so this dependency would probably work across processes, but this is on the same process), but something is not working right with an extension getting a data provider before another extension activates and registers that provider. She kept getting the following error:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Timeout reached when waiting for DataProvider-extensionTest.uidata to settle".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

When we wrapped the code getting the data provider in a 1-second setTimeout, the problem went away.

Seems there's a problem related to the AsyncVariables in the data provider service. Maybe some variable gets cached in get but isn't properly used in registerEngine or something. Note that the timeout is on DataProvider-extnesionTest.uidata, which seems to be related to the registerEngine.

Code Samples

Types in `paranext-ext-testing.d.ts` (Extension A)

declare module 'paranext-ext-testing' {
  type Ref = { bookNum: number; chapterNum: number; verseNum: number };

  type TestDataRow = {
    Id: string;
    FirstName: string;
    LastName: string;
    Zip: string;
  };

  export type UICompData = {
    TextValue: string;
    Slider: number;
    Switch: boolean;
    States: string[];
    Checkbox1: boolean;
    Checkbox2: boolean;
    Reference: Ref;
    TableData: TestDataRow[];
  };

  export type UICompDataTypes = {
    UIData: DataProviderDataType<string, UICompData, UICompData>;
  };

  export type UICompDataMethods = {
    sayHelloWithDataProvider(things: string): Promise<string>;
  };

  export type UICompDataProvider = IDataProvider<UICompDataTypes> & UICompDataMethods;
}

Accessing the data provider in Extension B

setTimeout(async () => {
    try {
      const dataProviderPromise1 =
        papi.dataProvider.get<UICompDataProvider>('extensionTest.uidata');
      const uiDataProvider1 = await dataProviderPromise1;
      logger.info('Extension Test UI Data provider : ' + uiDataProvider1);

      const greeting = await uiDataProvider1?.sayHelloWithDataProvider('Tester');
      logger.info(Method ${greeting});

      const data = await uiDataProvider1?.getUIData('*');
      if (data !== undefined) {
        logger.info(
          Values received from getUIData in Ext-Multiple-B  ${data.TextValue} States: ${data.States} Slider: ${data.Slider} Switch: ${data.Switch},
        );
      } else {
        logger.info('Did not get values in Ext-Multiple-B !!');
      }
    } catch (e) {
      logger.info('Failed to get UIDataProvider', e);
    }
  }, 1000);

@tjcouch-sil tjcouch-sil added this to the External Extension Ready milestone Sep 25, 2023
@tjcouch-sil tjcouch-sil moved this to Open in Paranext Sep 25, 2023
@GlennPruitt GlennPruitt moved this from Open to Product Backlog in Paranext Sep 25, 2023
@GlennPruitt GlennPruitt added the bug Something isn't working label Sep 28, 2023
@GlennPruitt GlennPruitt modified the milestones: External Extension Ready, Tech Demo Sep 28, 2023
@katherinejensen00 katherinejensen00 moved this from Product Backlog to 🔖 ToDo in Paranext Oct 4, 2023
@lyonsil lyonsil moved this from 🔖 ToDo to 🏗 In progress in Paranext Oct 5, 2023
@lyonsil lyonsil self-assigned this Oct 5, 2023
@lyonsil
Copy link
Member

lyonsil commented Oct 6, 2023

After some testing of my own, I can say it looks like this is a problem when you have Extension B open in VS Code and are debugging while loading Extension A via --extensionDirs. However, if you are running the platform and have both Extension A and Extension B packaged and loaded using --extensionDirs, everything seems to work fine.

@lyonsil lyonsil moved this from 🏗 In progress to 👀 In review in Paranext Oct 6, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Paranext Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants