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

Fails if XML file other than NUnit format is output to artifactsPath #285

Closed
nowsprinting opened this issue Nov 7, 2024 · 3 comments · Fixed by #286
Closed

Fails if XML file other than NUnit format is output to artifactsPath #285

nowsprinting opened this issue Nov 7, 2024 · 3 comments · Fixed by #286
Labels
bug Something isn't working

Comments

@nowsprinting
Copy link
Contributor

nowsprinting commented Nov 7, 2024

Bug description

Fails if XML file other than NUnit format is output to artifactsPath.

How to reproduce

Test outputs a file with a ".xml" extension other than the NUnit format.

Expected behavior

Ignore non-test result XML files.

Additional details

await Promise.all(
files.map(async filepath => {
if (!filepath.endsWith('.xml')) return;
core.info(`Processing file ${filepath}...`);
const fileData = await ResultsParser.parseResults(path.join(artifactsPath, filepath));
core.info(fileData.summary);
runs.push(fileData);
}),

@nowsprinting nowsprinting added the bug Something isn't working label Nov 7, 2024
@GabLeRoux
Copy link
Member

@coderabbitai, please review the file located at src/model/results-check.ts. There is an issue where files with a “.xml” extension, not in NUnit format, are causing errors when processed. Can you suggest a fix for this?

Copy link

coderabbitai bot commented Nov 8, 2024

Tip

For best results, initiate chat on the files or code changes.

@GabLeRoux, I see the issue in src/model/results-check.ts. The script processes all .xml files in the artifactsPath directory, assuming they are in NUnit format. This leads to errors when non-NUnit .xml files are encountered.

To fix this, you can modify the code to handle parsing errors gracefully by wrapping the parsing logic in a try-catch block. Here's how you might adjust your code:

// Parse all results files
const runs: RunMeta[] = [];
const files = fs.readdirSync(artifactsPath);
await Promise.all(
  files.map(async filepath => {
    if (!filepath.endsWith('.xml')) return;
    core.info(`Processing file ${filepath}...`);
    try {
      const fileData = await ResultsParser.parseResults(path.join(artifactsPath, filepath));
      core.info(fileData.summary);
      runs.push(fileData);
    } catch (error) {
      core.warning(`Failed to parse ${filepath}: ${error.message}`);
      // Optionally handle the error or skip the file
    }
  }),
);

By adding the try-catch block around the parsing function, the script will log a warning and continue processing other files if a file isn't in the expected NUnit format.

Let me know if this helps!

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Output the contents of src/model/results-check.ts
cat src/model/results-check.ts

Length of output: 4227

@nowsprinting
Copy link
Contributor Author

Thanks!!

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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants