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

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

Open
ivangsa opened this issue Dec 18, 2023 · 3 comments · May be fixed by #912
Open

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

ivangsa opened this issue Dec 18, 2023 · 3 comments · May be fixed by #912

Comments

@ivangsa
Copy link

ivangsa commented Dec 18, 2023

Description

As reported in VSCode AsyncAPI Preview:
asyncapi/vs-asyncapi-preview#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

@ashmit-coder
Copy link

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
Copy link

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

@ashmit-coder
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants