5 - Adding error handler for invalid YAML - #32
Conversation
| runSteps = yamlFile.run; | ||
| runStepNames = Object.keys(runSteps); | ||
| } catch (e) { | ||
| parseErrorMessage = e.message; |
There was a problem hiding this comment.
If there is an error loading the file is there any benefit in continuing? Wouldn't the first execute run test throw an error? which i see you catch below, but it might make more sense to just bail here.
There was a problem hiding this comment.
I was mostly thinking about the user experience, I wanted to still show the summary for the tests, wanted to give a stepName to this step of checking yml file as well instead of just bail over there.
If I just bail there, I would replace parseErrorMessage = e.message; by
logger.error(e.message);
process.exit(1);
the output for first approach is:
[INFO] Executing run step: parseYamlFile
[ERROR] FAILED "parseYamlFile": bad indentation of a mapping entry at line 5, column 3:
- /On branch ZZZ-[0-9]{0,10}\/no-id/
^ (1ms)
[SUMMARY] ============= JUDO TESTS COMPLETE =============
[SUMMARY] test-examples/wrong-yml.yml
[ERROR] FAILED: parseYamlFile (0.001s)
[SUMMARY] Total tests: 1 (0.001s)
[SUMMARY] Passed: 0
[SUMMARY] Failed: 1
and for the second approach is:
[ERROR] bad indentation of a mapping entry at line 5, column 3:
- /On branch ZZZ-[0-9]{0,10}\/no-id/
^
@worldjoe do you think I should use this second approach then? Thinking about the user, I would prefer the first but it is up to you.
|
Adding a special named step seems like a bit of a hack. Getting the line number and preview here is great, but from the user's perspective I'd want the output to be something unique to when parse errors occur to make it more clear |
|
Okay so I just added a The output would be this for a invalid yaml file: |
ejfrancis
left a comment
There was a problem hiding this comment.
ran it locally and everything looks good. thanks for the contribution!
npm run lint?fix/12-some-bugAs right now, the fix is basically adding the
parseYamlFileas a first step for every file, the step will verify the current yaml, if it fails I get the exception message and add it as the reason for the test to fail which indicates the line and column from the invalid yaml file, if there is an invalid yaml file, the test will stop right away. Check the outputs below:====================== OUTPUTS =====================
Single invalid yaml file fails:
Single file test succeeds:
Directory tests fail with both invalid yaml and invalid step output: