Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions BUGS_AND_ISSUES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Potential Bugs and Issues

This document lists important bugs and issues found in the cordova-plugin-firebasex repository that should be fixed.

## Critical Issues

### 1. Unreachable Code in `scripts/post_install.js` - `handleError` function
**File:** `scripts/post_install.js` (lines 123-129)
**Severity:** High

The `handleError` function has unreachable code due to a `return` statement before `throw`:

```javascript
const handleError = function (errorMsg, errorObj) {
errorMsg = PLUGIN_NAME + " - ERROR: " + errorMsg;
console.error(errorMsg);
console.dir(errorObj);
return errorMsg; // <-- This return statement
throw errorObj; // <-- This throw will never execute!
};
```

**Impact:** Errors are not being thrown as intended, which means error handling may silently fail.

**Fix:** Remove the `return errorMsg;` line (line 127) so the `throw` can execute.

---

### 2. Missing Variable Declaration in `scripts/post_install.js` - `parseConfigXml` function
**File:** `scripts/post_install.js` (line 199)
**Severity:** High

The variable `data` is used without declaration, making it an implicit global variable:

```javascript
const parseConfigXml = function(){
if(configXmlData) return configXmlData;
try{
data = parseXmlFileToJson(configXmlPath); // <-- Missing 'const' or 'let'
configXmlData = data.xml;
return configXmlData;
}catch (e){
console.warn("Failed to parse config.xml: " + e.message);
}
};
```

**Impact:** Creates an implicit global variable which is a JavaScript anti-pattern and can cause unexpected behavior in strict mode.

**Fix:** Add `const` before `data` on line 199: `const data = parseXmlFileToJson(configXmlPath);`

---

## Medium Priority Issues

### 3. Potential Race Condition in `src/android/FirebasePlugin.java` - Synchronized Block
**File:** `src/android/FirebasePlugin.java` (lines 3828-3833, 3843-3850)
**Severity:** Medium

The code synchronizes on the class object (`FirebasePlugin.class`) rather than an instance lock:

```java
synchronized (FirebasePlugin.class) {
if (pendingGlobalJS == null) {
pendingGlobalJS = new ArrayList<>();
}
pendingGlobalJS.add(jsString);
}
```

**Impact:** Synchronizing on the class object means all instances of the plugin share the same lock, which could cause performance issues if multiple plugin instances exist. Additionally, `pendingGlobalJS` appears to be an instance variable, but it's being synchronized using a class lock.

**Fix:** Consider using a dedicated instance lock object or synchronizing on `this` if `pendingGlobalJS` is an instance variable. Also verify if `pendingGlobalJS` should be static or instance-level.

---

### 4. Missing Return Value in `README.md` - Documentation Error
**File:** `README.md` (logError example)
**Severity:** Low-Medium

The `window.onerror` example doesn't return a value, which means the error will propagate to the browser's default error handler:

```javascript
window.onerror = function (errorMsg, url, line, col, error) {
// ... error handling code ...
// Missing return statement!
};
```

**Impact:** The browser will still display the error in the console even after it's been logged to Firebase, which may confuse developers.

**Fix:** Add `return true;` at the end of the `window.onerror` function to prevent the error from propagating to the default handler. Document this behavior.

---

### 5. Inconsistent Variable Declaration in `scripts/lib/utilities.js`
**File:** `scripts/lib/utilities.js` (lines 124, 127)
**Severity:** Low

The code mixes `const` and `var` for loop variables:

```javascript
for(const pluginId in packageJSON.cordova.plugins){
if(pluginId === Utilities.getPluginId()){
for(const varName in packageJSON.cordova.plugins[pluginId]){
var varValue = packageJSON.cordova.plugins[pluginId][varName]; // <-- uses 'var'
pluginVariables[varName] = varValue;
}
}
}
```

**Impact:** Inconsistent code style, though not a functional bug.

**Fix:** Change `var varValue` to `const varValue` for consistency.

---

## Low Priority / Code Quality Issues

### 6. Empty Catch Block in `scripts/lib/utilities.js` - `copyKey` function
**File:** `scripts/lib/utilities.js` (lines 150-152)
**Severity:** Low

```javascript
try{
var destinationPath = platform.dest;
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/'));
fs.ensureDirSync(folder);
fs.writeFileSync(path.resolve(destinationPath), contents);
}catch(e){
// skip <-- Empty catch block with just a comment
}
```

**Impact:** Silent failures make debugging difficult. If the file write fails, there's no indication of why.

**Fix:** At minimum, log the error. Better yet, handle it appropriately or re-throw if it should propagate.

---

### 7. Potential Null Pointer in `scripts/ios/before_plugin_install.js`
**File:** `scripts/ios/before_plugin_install.js` (line 16)
**Severity:** Low

```javascript
version = execSync('pod --version', {encoding: 'utf8'}).match(/(\d+\.\d+\.\d+)/)[1];
```

**Impact:** If the regex doesn't match, `.match()` returns `null`, and accessing `[1]` will throw a TypeError. While the catch block handles this, the error message would be confusing.

**Fix:** Check if match result is null before accessing array index, or provide a more specific error message.

---

### 8. Missing Null Check in `scripts/lib/utilities.js` - `parsePackageJson`
**File:** `scripts/lib/utilities.js` (lines 122-131)
**Severity:** Low

```javascript
var packageJSON = Utilities.parsePackageJson();
if(packageJSON.cordova && packageJSON.cordova.plugins){
// ... code that accesses packageJSON.cordova.plugins
}
```

**Impact:** If `parsePackageJson()` returns `{}` (which it does when package.json doesn't exist), this code works fine. However, there's a subtle assumption that should be documented.

**Fix:** This is actually handled correctly, but could benefit from a comment explaining the behavior.

---

## Summary

**Critical fixes needed:**
1. Remove unreachable code in `handleError` function (post_install.js)
2. Add missing variable declaration in `parseConfigXml` (post_install.js)

**Important improvements:**
3. Fix synchronization strategy in FirebasePlugin.java
4. Add return value to window.onerror example in README.md

**Code quality improvements:**
5. Make variable declarations consistent
6. Add error logging to empty catch blocks
7. Add null checks for regex matches

These issues range from critical bugs that prevent proper error handling to code quality improvements that make the codebase more maintainable and robust.