Skip to content

Fix: callback not invoked on Dropbox filesDownload error in Store.js#8

Merged
Samuel3 merged 4 commits into
feature/add-testsfrom
copilot/sub-pr-5-another-one
Mar 30, 2026
Merged

Fix: callback not invoked on Dropbox filesDownload error in Store.js#8
Samuel3 merged 4 commits into
feature/add-testsfrom
copilot/sub-pr-5-another-one

Conversation

Copilot AI commented Feb 28, 2026

Copy link
Copy Markdown
Contributor
  • Analyze the issue: callback not invoked on filesDownload error in Store.js
  • Fix Store.js to call callback in the .catch handler
  • Add tests for Dropbox error/success callback invocation
  • Run tests to validate the fix (49/49 passing)
  • Fix CI build: regenerate package-lock.json with complete dependency tree
  • Guard callback.call(self) with typeof callback === 'function' in both .then and .catch handlers to prevent TypeError when no callback is provided
  • Replace new Blob(...) with plain {} object in test to avoid ReferenceError in older Node environments
  • Code review and security check (no issues found)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Samuel3 <15921086+Samuel3@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback from review on adding tests feature Fix: callback not invoked on Dropbox filesDownload error in Store.js Feb 28, 2026
@Samuel3

Samuel3 commented Mar 1, 2026

Copy link
Copy Markdown
Owner

@copilot please fix build

Co-authored-by: Samuel3 <15921086+Samuel3@users.noreply.github.com>

Copilot AI commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please fix build

Fixed in commit 6558261. The build was failing because running npm install --save-dev mocha@5 in the previous session upgraded package-lock.json from lockfileVersion 1 to 3, but the resulting file was missing packages like lodash.isplainobject that npm ci requires. Regenerated the lock file with npm install --package-lock-only --ignore-scripts to produce a complete dependency tree.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Store initialization edge case where the provided callback was not invoked when Dropbox filesDownload fails, and adds regression tests around Dropbox initialization behavior.

Changes:

  • Invoke the Store initialization callback from the Dropbox filesDownload .catch(...) handler.
  • Add unit tests verifying callback invocation on Dropbox download success and failure.
  • Update Mocha devDependency version.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
app/js/Store.js Ensures the initialization callback is triggered when Dropbox download rejects.
test/store.test.js Adds Dropbox init tests to assert callback invocation for success/error paths.
package.json Bumps Mocha version used for running tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/js/Store.js Outdated
Comment on lines +29 to +33
@@ -30,6 +30,7 @@ var Store = function (callback) {
if (JSON.parse(error.error).error_summary !== "path/not_found/..") {
ipcRenderer.send('message', i18n("message.dropboxfailed"));
}
setTimeout(function() { callback.call(self); }, 1);

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

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

callback is invoked unconditionally here. If Store is constructed without a callback (the constructor already treats it as optional in the non-Dropbox path), this will throw a TypeError. Guard the invocation (e.g., only call when callback is a function) or provide a no-op default so the Dropbox error path can’t crash the app.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot please fix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit e713b5d. Both the .then (loadend) and .catch handlers now guard with typeof callback === 'function' before invoking callback.call(self).

Comment thread test/store.test.js Outdated
Comment on lines +370 to +371
return Promise.resolve({
fileBlob: new Blob([JSON.stringify({})], { type: 'application/json' })

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

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

This test uses new Blob(...), but the unit tests run under plain Node (and this repo’s CI/build config includes Node 10 on Windows), where Blob is not available. Since the FileReader mock ignores the argument anyway, return a simple placeholder (or add a global.Blob polyfill in the test setup) to avoid ReferenceError: Blob is not defined in older Node environments.

Suggested change
return Promise.resolve({
fileBlob: new Blob([JSON.stringify({})], { type: 'application/json' })
// Use a simple placeholder instead of Blob to avoid ReferenceError in Node
return Promise.resolve({
fileBlob: {}

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot please fix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit e713b5d. Replaced new Blob([JSON.stringify({})], { type: 'application/json' }) with a plain {} object, which avoids the ReferenceError in Node environments where Blob is not globally available.

… in test

Co-authored-by: Samuel3 <15921086+Samuel3@users.noreply.github.com>
@Samuel3 Samuel3 marked this pull request as ready for review March 30, 2026 18:48
@Samuel3 Samuel3 merged commit e90b060 into feature/add-tests Mar 30, 2026
2 checks passed
@Samuel3 Samuel3 deleted the copilot/sub-pr-5-another-one branch March 30, 2026 18:49
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.

3 participants