Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Dec 1, 2025

User description

Logging to try to resolve an error with the alignment tab not loading.


PR Type

Bug fix


Description

  • Add null checks for magnetometer alignment data retrieval

  • Log console messages when sensor alignment values are null

  • Prevent potential runtime errors from null/undefined data

  • Add defensive check in board roll axis update function


Diagram Walkthrough

flowchart LR
  A["getSetting calls<br/>align_mag_roll/pitch/yaw"] --> B["Check if data<br/>is null"]
  B --> C["Log console<br/>message if null"]
  C --> D["Parse value<br/>safely"]
  E["updateBoardRollAxis<br/>function"] --> F["Check if value<br/>is null"]
  F --> G["Log console<br/>message if null"]
Loading

File Walkthrough

Relevant files
Bug fix
magnetometer.js
Add null checks and error logging for alignment data         

tabs/magnetometer.js

  • Add null/undefined checks for align_mag_roll, align_mag_pitch, and
    align_mag_yaw settings retrieval
  • Add console logging when sensor alignment data is null to aid
    debugging
  • Add null check in updateBoardRollAxis function with console logging
  • Prevent potential runtime errors from attempting to parse null values
+13/-0   

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Branch Targeting Suggestion

You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:

  • maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

  • maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If master is the correct target for this change, no action is needed.


This is an automated suggestion to help route contributions to the appropriate branch.

@sensei-hacker sensei-hacker changed the base branch from master to maintenance-9.x December 1, 2025 17:15
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 1, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Excessive console logging

Description: The code logs potentially sensitive runtime state directly to the console, which may leak
internal details in production and aid fingerprinting or debugging by attackers; guard
debug logs behind environment checks or remove them for production.
magnetometer.js [61-81]

Referred Code
        if (data == null) {
            console.log("while settting align_mag_roll, data is null or undefined");
        }
        self.alignmentConfig.roll = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_pitch").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_pitch, data is null or undefined");
        }
        self.alignmentConfig.pitch = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_yaw").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_yaw, data is null or undefined");
        }
        self.alignmentConfig.yaw = parseInt(data.value, 10) / 10;
    }).then(callback)
Information disclosure via logs

Description: Added console logging of null input in a user-influenced function may expose internal flow
information in production; consider restricting such logs to debug builds.
magnetometer.js [254-256]

Referred Code
if (value == null) {
    console.log("in updateBoardRollAxis, value is null or undefined");
}
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

🔴
Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status:
Unstructured logging: New console logs are unstructured strings without consistent fields, making them difficult
to parse and monitor per secure logging best practices.

Referred Code
        if (data == null) {
            console.log("while settting align_mag_roll, data is null or undefined");
        }
        self.alignmentConfig.roll = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_pitch").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_pitch, data is null or undefined");
        }
        self.alignmentConfig.pitch = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_yaw").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_yaw, data is null or undefined");
        }
        self.alignmentConfig.yaw = parseInt(data.value, 10) / 10;
    }).then(callback)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Non-audited logs: The added console logs record null sensor alignment conditions but do not constitute
structured, attributable audit records with user IDs and timestamps for critical actions.

Referred Code
        if (data == null) {
            console.log("while settting align_mag_roll, data is null or undefined");
        }
        self.alignmentConfig.roll = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_pitch").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_pitch, data is null or undefined");
        }
        self.alignmentConfig.pitch = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_yaw").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_yaw, data is null or undefined");
        }
        self.alignmentConfig.yaw = parseInt(data.value, 10) / 10;
    }).then(callback)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Weak null handling: Null cases are logged but parsing still proceeds on possibly null 'data' (e.g.,
accessing data.value) and no fallback or early return prevents runtime errors.

Referred Code
        if (data == null) {
            console.log("while settting align_mag_roll, data is null or undefined");
        }
        self.alignmentConfig.roll = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_pitch").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_pitch, data is null or undefined");
        }
        self.alignmentConfig.pitch = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_yaw").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_yaw, data is null or undefined");
        }
        self.alignmentConfig.yaw = parseInt(data.value, 10) / 10;
    }).then(callback)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Missing validation: The code checks for null but still uses 'data.value' without validating
type/format or providing safe defaults, which may allow undefined or invalid inputs to
propagate.

Referred Code
        if (data == null) {
            console.log("while settting align_mag_roll, data is null or undefined");
        }
        self.alignmentConfig.roll = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_pitch").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_pitch, data is null or undefined");
        }
        self.alignmentConfig.pitch = parseInt(data.value, 10) / 10;
    }).then(callback)
},
function (callback) {
    mspHelper.getSetting("align_mag_yaw").then(function (data) {
        if (data == null) {
            console.log("while settting align_mag_yaw, data is null or undefined");
        }
        self.alignmentConfig.yaw = parseInt(data.value, 10) / 10;
    }).then(callback)

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 1, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent runtime error after null check
Suggestion Impact:The commit added return statements inside the if (data == null)/(value == null) blocks, preventing subsequent property access and potential crashes, matching the suggestion.

code diff:

             mspHelper.getSetting("align_mag_roll").then(function (data) {
                 if (data == null) {
                     console.log("while settting align_mag_roll, data is null or undefined");
+                    return;
                 }
                 self.alignmentConfig.roll = parseInt(data.value, 10) / 10;
             }).then(callback)
@@ -68,6 +69,7 @@
             mspHelper.getSetting("align_mag_pitch").then(function (data) {
                 if (data == null) {
                     console.log("while settting align_mag_pitch, data is null or undefined");
+                    return;
                 }
                 self.alignmentConfig.pitch = parseInt(data.value, 10) / 10;
             }).then(callback)
@@ -76,6 +78,7 @@
             mspHelper.getSetting("align_mag_yaw").then(function (data) {
                 if (data == null) {
                     console.log("while settting align_mag_yaw, data is null or undefined");
+                    return;
                 }
                 self.alignmentConfig.yaw = parseInt(data.value, 10) / 10;
             }).then(callback)
@@ -253,6 +256,7 @@
     function updateBoardRollAxis(value) {
         if (value == null) {
             console.log("in updateBoardRollAxis, value is null or undefined");
+            return;
         }
 
         self.boardAlignmentConfig.roll = Number(value);

Add a return statement inside the if (data == null) block to prevent a runtime
crash from accessing a property on a null object.

tabs/magnetometer.js [61-64]

 if (data == null) {
     console.log("while settting align_mag_roll, data is null or undefined");
+    return;
 }
 self.alignmentConfig.roll = parseInt(data.value, 10) / 10;

[Suggestion processed]

Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical bug where the application would crash with a TypeError if data is null, because the execution flow isn't stopped after the null check.

High
Avoid unintended behavior with null values
Suggestion Impact:The commit added a return inside the if (value == null) block in updateBoardRollAxis, preventing unintended assignment. Similar returns were also added for related settings.

code diff:

@@ -253,6 +256,7 @@
     function updateBoardRollAxis(value) {
         if (value == null) {
             console.log("in updateBoardRollAxis, value is null or undefined");
+            return;
         }
 
         self.boardAlignmentConfig.roll = Number(value);

Add a return statement inside the if (value == null) block to prevent
self.boardAlignmentConfig.roll from being unintentionally set to 0 when value is
null.

tabs/magnetometer.js [254-258]

 if (value == null) {
     console.log("in updateBoardRollAxis, value is null or undefined");
+    return;
 }
 
 self.boardAlignmentConfig.roll = Number(value);

[Suggestion processed]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that not returning after the null check will cause self.boardAlignmentConfig.roll to be silently set to 0, which is unintended behavior and a potential bug.

Medium
  • Update

@sensei-hacker
Copy link
Member Author

Needed because these settings can come back empty. Todo: See if it's a problem that they back back empty.

@sensei-hacker sensei-hacker merged commit 689378c into iNavFlight:maintenance-9.x Dec 3, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant