webui: show error when JSON does not follow expected result document schema#2871
Conversation
Summary of ChangesHello @devs6186, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the web UI would silently fail or show misleading errors when attempting to load JSON files that were syntactically valid but did not adhere to the expected capa result document schema. By introducing explicit schema validation and more informative error messages, the changes significantly improve the user experience by providing clearer feedback and actionable advice, especially for data loaded from external URL sources. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces schema validation for loaded JSON files, which is a great improvement for error handling. I've identified a potential bug in the validation logic where an array could be incorrectly treated as a valid object, and I've provided a suggestion to fix it. Additionally, I've suggested a refactoring to improve maintainability by removing a duplicated error message string. Overall, these are solid changes that enhance the tool's robustness and user experience.
- introduce isInvalidObject() helper (checks !v || typeof !== "object" || Array.isArray) so that arrays are correctly rejected in schema validation - extract VT_REANALYZE_SUGGESTION constant to eliminate the duplicated string in loadRdoc() Addresses review feedback on mandiant#2871
|
Thanks for the thorough review, @gemini-code-assist! Both suggestions have been addressed in the latest commit ( [High] Array validation bug in const isInvalidObject = (v) => !v || typeof v !== "object" || Array.isArray(v);All six object-field checks now use this helper, so a field that is an array (e.g. [Medium] Duplicated VirusTotal suggestion string in const VT_REANALYZE_SUGGESTION =
" If this is a VirusTotal or similar link, the file may need to be reanalyzed. Try again later.";Both branches now reference ESLint and vitest both pass clean after the changes. Please take another look when you get a chance. |
There was a problem hiding this comment.
Code Review
This pull request introduces schema validation for loaded JSON result documents, which is a great improvement for error handling and user experience. When a document doesn't match the expected schema, a clear error message is now displayed. The change also includes a helpful suggestion to reanalyze files from sources like VirusTotal in case of parsing or validation errors.
My review includes a suggestion to enhance the schema validation to cover another field that is used later in the application, which will prevent potential runtime errors. I've also included a minor suggestion to improve code organization by moving a constant to a more appropriate scope.
|
Thanks for the review. I’ve applied both suggestions: feature_counts validation – validateRdocSchema() now checks that meta.analysis.feature_counts exists and is an object, and that it has either a functions or processes array (for static vs dynamic docs). That way parseFunctionCapabilities and anything else that reads doc.meta.analysis.feature_counts won’t run on invalid or incomplete JSON, and we show a clear validation error instead of a runtime error later. VT_REANALYZE_SUGGESTION – Moved to module scope at the top of useRdocLoader.js so it’s defined once instead of on every loadRdoc call. Changes are pushed; happy to adjust wording or validation rules if you’d like. |
Validate result document has required fields (meta, meta.version, meta.analysis, meta.analysis.layout, rules) after parse. Show user-friendly error; for URL loads suggest reanalyzing (e.g. VT). Fixes mandiant#2363
- introduce isInvalidObject() helper (checks !v || typeof !== "object" || Array.isArray) so that arrays are correctly rejected in schema validation - extract VT_REANALYZE_SUGGESTION constant to eliminate the duplicated string in loadRdoc() Addresses review feedback on mandiant#2871
…UGGESTION - Add validation for meta.analysis.feature_counts in validateRdocSchema() so parseFunctionCapabilities and other consumers do not hit missing/invalid feature_counts at runtime. - Require feature_counts to have either 'functions' or 'processes' array (static vs dynamic result documents). - Move VT_REANALYZE_SUGGESTION to module top level to avoid redefining on every loadRdoc call.
- Validation: allow feature_counts without functions/processes arrays; if present they must be arrays. - rdocParser: default feature_counts.functions to [] when missing so file-scoped-only docs do not throw.
Per review feedback: the concatenation at call sites handles spacing, so the constant should not carry a leading space.
60e4336 to
42f1574
Compare
|
Hi @fariss , could I please get another set of eyes on these changes? |
|
Hi @devs6186 thanks for the implementation and @mike-hunhoff for the review. I've tested this locally by generating test files (for example, |
You rock @fariss , thank you! |
…schema (mandiant#2871) * webui: show error when JSON does not follow expected schema Validate result document has required fields (meta, meta.version, meta.analysis, meta.analysis.layout, rules) after parse. Show user-friendly error; for URL loads suggest reanalyzing (e.g. VT). Fixes mandiant#2363 * webui: fix array validation bug and deduplicate VT suggestion string - introduce isInvalidObject() helper (checks !v || typeof !== "object" || Array.isArray) so that arrays are correctly rejected in schema validation - extract VT_REANALYZE_SUGGESTION constant to eliminate the duplicated string in loadRdoc() Addresses review feedback on mandiant#2871 * webui: address review - validate feature_counts, hoist VT_REANALYZE_SUGGESTION - Add validation for meta.analysis.feature_counts in validateRdocSchema() so parseFunctionCapabilities and other consumers do not hit missing/invalid feature_counts at runtime. - Require feature_counts to have either 'functions' or 'processes' array (static vs dynamic result documents). - Move VT_REANALYZE_SUGGESTION to module top level to avoid redefining on every loadRdoc call. * webui: allow file-scoped-only result documents in schema validation - Validation: allow feature_counts without functions/processes arrays; if present they must be arrays. - rdocParser: default feature_counts.functions to [] when missing so file-scoped-only docs do not throw. * webui: remove leading space from VT_REANALYZE_SUGGESTION constant Per review feedback: the concatenation at call sites handles spacing, so the constant should not carry a leading space.
closes #2363
When a user loads a JSON file (from disk or URL) that is valid JSON but does not match the capa result document schema, the web explorer silently fails or shows a misleading error. This makes it hard to diagnose issues, especially with links from VirusTotal or other services that may return stale/incomplete data.
Changes
validateRdocSchema()inuseRdocLoader.jsthat checks for the required fields:meta,meta.version,meta.analysis,meta.analysis.layout, andrules.JSON.parse, validation runs before any further processing.Checklist