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

Add warning for invalid nunit xml files #286

Merged
merged 5 commits into from
Nov 8, 2024

Conversation

GabLeRoux
Copy link
Member

@GabLeRoux GabLeRoux commented Nov 8, 2024

Closes #285

This pull request includes a change to the src/model/results-check.ts file to improve error handling when parsing XML files.

Error handling improvement:

  • src/model/results-check.ts: Added a try-catch block to handle errors during the parsing of XML files, logging a warning message if parsing fails.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling during results file parsing to prevent complete failure when encountering problematic files.
    • Added logging for parsing errors to improve visibility and troubleshooting.

These changes enhance the reliability of file processing, ensuring smoother operation and better user experience.

Copy link

coderabbitai bot commented Nov 8, 2024

Walkthrough

The changes in this pull request enhance error handling in the createCheck method of the ResultsCheck object located in src/model/results-check.ts. A try-catch block has been introduced to manage errors encountered during the parsing of results files. If a file fails to parse, a warning is logged, allowing the process to continue with other files rather than terminating. The fundamental logic for aggregating results and interacting with the GitHub API remains unchanged.

Changes

File Change Summary
src/model/results-check.ts Added a try-catch block in createCheck method for error handling during results file parsing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ResultsCheck
    participant FileParser
    participant Logger

    User->>ResultsCheck: Initiate createCheck
    ResultsCheck->>FileParser: Parse results files
    alt Parsing successful
        FileParser-->>ResultsCheck: Return parsed data
    else Parsing error
        FileParser-->>ResultsCheck: Return error
        ResultsCheck->>Logger: Log warning about parsing error
    end
    ResultsCheck-->>User: Return summary of results
Loading

Assessment against linked issues

Objective Addressed Explanation
Ignore non-test result XML files (#285)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9b7d89c and cfdf16b.

📒 Files selected for processing (1)
  • src/model/results-check.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/model/results-check.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@GabLeRoux GabLeRoux changed the title fix/add warning for invalid nunit xml files Add warning for invalid nunit xml files Nov 8, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
src/model/results-check.ts (1)

25-31: Consider enhancing error reporting and tracking.

While the current implementation catches errors, it could be improved to provide better visibility into parsing issues:

  1. Track the number of failed files
  2. Include parsing failures in the final summary
  3. Distinguish between different types of errors (invalid XML vs non-NUnit format)
 const runs: RunMeta[] = [];
+const parsingErrors: Array<{file: string, error: string}> = [];
 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: any) {
       core.warning(`Failed to parse ${filepath}: ${error.message}`);
+      parsingErrors.push({ file: filepath, error: error.message });
     }
   }),
 );

+// Add parsing errors to the summary if any occurred
+if (parsingErrors.length > 0) {
+  core.warning(`Failed to parse ${parsingErrors.length} file(s)`);
+  runSummary.addParsingErrors(parsingErrors);
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 05a00ef and 7386cbe.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (1)
  • src/model/results-check.ts (1 hunks)
🔇 Additional comments (2)
src/model/results-check.ts (2)

25-31: LGTM! Error handling implementation looks good.

The try-catch block appropriately handles parsing failures and allows processing to continue with other files.


25-31: Verify the impact on test results reporting.

The error handling might affect how test results are reported to GitHub Checks API. Let's verify the implementation of ResultsParser to ensure it properly distinguishes between different error types.

✅ Verification successful

Let me gather more information about the ResultsParser implementation and error handling.


Based on the implementation details and tests, I can now provide the final response:

Error handling in ResultsParser is robust and properly integrated with GitHub Checks API

The error handling implementation is well-designed and properly handles test results reporting:

  • File parsing errors are caught and logged as warnings, allowing other test files to be processed
  • Test failures are properly captured with detailed stack traces and console output
  • Failed tests are correctly converted to GitHub Check annotations with proper file paths and line numbers
  • The implementation includes comprehensive test coverage for various error scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ResultsParser implementation and error handling
ast-grep --pattern 'class ResultsParser {
  $$$
  parseResults($$$) {
    $$$
  }
  $$$
}'

# Look for existing error handling in test files
rg -g "*.test.ts" "ResultsParser.parseResults"

Length of output: 494


Script:

#!/bin/bash
# Get the implementation of ResultsParser class
cat src/model/results-parser.ts

# Look for test files content to understand error scenarios
cat src/model/results-parser.test.ts

# Check if there are any GitHub Checks API related files
fd "check" --type f --exec cat {}

Length of output: 20115

src/model/results-check.ts Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Nov 8, 2024

Cat Gif

Copy link
Contributor

@nowsprinting nowsprinting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GabLeRoux GabLeRoux enabled auto-merge (squash) November 8, 2024 21:58
Copy link
Member

@webbertakken webbertakken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/model/results-check.ts Show resolved Hide resolved
src/model/results-check.ts Show resolved Hide resolved
@GabLeRoux GabLeRoux merged commit 0483262 into main Nov 8, 2024
85 of 86 checks passed
@GabLeRoux GabLeRoux deleted the fix/add-warning-for-invalid-nunit-xml-files branch November 8, 2024 22:43
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 this pull request may close these issues.

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