asyncapi-react icon indicating copy to clipboard operation
asyncapi-react copied to clipboard

Option "errors: true" shows empty/blank page when document has errors

Open ivangsa opened this issue 1 year ago • 4 comments

Description

As reported in VSCode AsyncAPI Preview: https://github.com/asyncapi/vs-asyncapi-preview/issues/200

After upgrading to latest: "@asyncapi/react-component": "^1.2.7"

It shows a blank page when document contains validation errors

This are the configuration options used: image

ivangsa avatar Dec 18 '23 08:12 ivangsa

hey @ivangsa The issue seems to occur due to unhandled undefined of the document object

try {
      const { document } = await asyncapiParser.parse(content, parserOptions);
      return { asyncapi: document };
    } catch (err) {
      return this.handleError(err as ErrorObject);
    }

Here the document object turns out undefined and hence no error is thrown.

try {
      const parseResult = await asyncapiParser.parse(content, parserOptions);

      let error:({title:string} ) = {title:""};
      if(parseResult.document === undefined) {

        parseResult.diagnostics.forEach(diagnostic => {
          if(diagnostic.code.toString().includes("error")) {
            error.title = diagnostic.message.toString();
          }
        });

        if(error.title === "") {
          error.title = "Unexpected error while parsing the document.";
        }

        throw error;
      }

      return { asyncapi: parseResult.document };
    } catch (err) {
      return this.handleError(err as ErrorObject);
    }

This is one way we could resolve this issue.

I will draft a PR for the same and we can communicate over it.

ashmit-coder avatar Feb 05 '24 12:02 ashmit-coder

Hey @derberg if you may help guide through this it will be great.

ashmit-coder avatar Feb 05 '24 17:02 ashmit-coder

This maybe an upstream error as the parser does not throw an error as of the latest version but rather an undefined document object witth a error message in the diganostic object

ashmit-coder avatar Feb 21 '24 08:02 ashmit-coder

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Jun 21 '24 00:06 github-actions[bot]