Skip to content

refactor: Improve error message for invalid YAML syntax #2

@ioncakephper

Description

@ioncakephper

Is your feature request related to a problem?

Currently, if a user tries to validate a file that contains invalid YAML syntax, the application may crash or
produce a complex error message from the js-yaml library. We should handle this gracefully and provide a clear,
user-friendly error message.

Describe the solution you'd like

Tasks:

  1. In src/validate.js, locate the yaml.load() call within the validateYaml function.
  2. Wrap this call in a try...catch block.
  3. In the catch block, check if the error is a YAML parsing error.
  4. If it is, return an object in the same format as a validation failure, but with a custom error message,
    e.g., { valid: false, errors: [{ message: 'The provided file is not a valid YAML document. Please check its
    syntax.' }] }.
  5. Update the tests in test/validate.test.js to include a new test case that asserts this user-friendly error
    is returned when trying to validate a syntactically incorrect YAML file.

Describe alternatives you've considered

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions