Fix Math Brain Data Import Failure#305
Conversation
This commit addresses an issue where the Math Brain would fail during data import due to incomplete house cusp data from the upstream API. The `extractHouseCusps` function has been modified to gracefully handle missing house cusps. Instead of returning `null`, it now returns an object containing the cusps that were found and an array of the missing ones. The `fetchNatalChartComplete` function has been updated to handle the new return format from `extractHouseCusps`, ensuring that incomplete data is processed without causing downstream errors. The `calculateNatalHouse` function has also been updated to be backward-compatible with the new data structure, ensuring that the application remains functional after the refactoring.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
✅ Deploy Preview for sprightly-genie-998c07 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the Math Brain's house cusp data processing by gracefully handling incomplete or missing house cusp data from upstream APIs, preventing failures and improving system stability.
Key Changes:
- Modified
extractHouseCusps()to return an object containing both found cusps and missing cusp names instead of null for incomplete data - Updated
calculateNatalHouse()to handle house cusps in both array and object formats - Enhanced error logging to track missing house cusps while continuing processing
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/math-brain/utils/compression.js | Refactored house cusp extraction to return partial data with missing indicators and updated house calculation to handle multiple data formats |
| src/math-brain/api-client.js | Updated natal chart processing to handle new house cusp result format and log missing cusps as warnings |
| package.json | Removed extraneous blank lines from npm scripts section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ? Object.values(houseCusps).map(c => c.abs_pos) | ||
| : null); | ||
|
|
||
| if (!cuspValues || cuspValues.length < 12 || typeof transitLongitude !== 'number') { |
There was a problem hiding this comment.
The validation changed from !== 12 to < 12, allowing incomplete house data (e.g., 11 cusps) to pass validation. This could cause index out-of-bounds errors at line 123 when accessing cuspValues[(i + 1) % 12] if fewer than 12 cusps are present. Either restore the strict !== 12 check or add bounds validation in the loop.
| if (!cuspValues || cuspValues.length < 12 || typeof transitLongitude !== 'number') { | |
| if (!cuspValues || cuspValues.length !== 12 || typeof transitLongitude !== 'number') { |
| } | ||
|
|
||
| return cusps.length === 12 ? cusps : null; | ||
| return { cusps, missing }; |
There was a problem hiding this comment.
The function's return type changed from number[]|null (as documented in the JSDoc at line 146) to an object with {cusps, missing} properties. The JSDoc must be updated to reflect the new return type: @returns {{cusps: Object, missing: string[]}|null}.

This commit fixes a bug that caused the Math Brain to fail when processing incomplete house cusp data. The changes ensure that the application can gracefully handle missing data from the upstream API, preventing unexpected failures and improving the overall stability of the system.
Fixes #
PR created automatically by Jules for task 1541907969709352006 started by @DHCross