Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No update-info.json file in update cache folder 😶 #4928

Closed
b-zurg opened this issue May 5, 2020 · 4 comments · Fixed by #4929
Closed

No update-info.json file in update cache folder 😶 #4928

b-zurg opened this issue May 5, 2020 · 4 comments · Fixed by #4929

Comments

@b-zurg
Copy link
Contributor

b-zurg commented May 5, 2020

  • electron-builder: "22.5.1"
  • Electron Version: 8.2.2
  • Electron Type: current
  • electron-updater: "4.2.5"
  • Target: windows

I'm seeing this error after uploading a new version to an S3 bucket.

The upload went fine and all of the artifacts are there as far as I can tell.

Here is the log of the local application (output to AppData log.log from electron-log logger)

[2020-05-05 22:41:04.824] [info] Checking for update
[2020-05-05 22:41:05.017] [info] Generated new staging user ID: 586a9abf-80b7-5cb4-a8db-9af47cc1d5a7
[2020-05-05 22:41:06.100] [info] Found version 0.0.2-beta (url: MyApp Setup 0.0.2-beta.exe)
[2020-05-05 22:41:06.252] [info] Downloading update from MyApp Setup 0.0.2-beta.exe
[2020-05-05 22:41:06.273] [debug] updater cache dir: C:\Users\zurg\AppData\Local\app.com.org-updater
[2020-05-05 22:41:07.510] [error] Error: TypeError: Cannot read property 'fileName' of undefined
    at t.DownloadedUpdateHelper.cachedUpdateFile [as getValidCachedUpdateFile] (C:\Users\zurg\AppData\Local\Programs\app.com.org\resources\app.asar\.webpack\main\webpack:\node_modules\electron-updater\out\DownloadedUpdateHelper.js:149:20)
    at t.DownloadedUpdateHelper.cachedUpdateFile [as validateDownloadedPath] (C:\Users\zurg\AppData\Local\Programs\app.com.org\resources\app.asar\.webpack\main\webpack:\node_modules\electron-updater\out\DownloadedUpdateHelper.js:88:11)
    at b.executeDownload (C:\Users\zurg\AppData\Local\Programs\app.com.org\resources\app.asar\.webpack\main\webpack:\node_modules\electron-updater\out\AppUpdater.js:726:11)
[2020-05-05 22:41:07.522] [info] Updating **with** synchronization
[2020-05-05 22:41:07.832] [error] TYPE should be object

After looking at the source code the only place the fileName property is accessed is here:

    if (cachedInfo.fileName == null) {
      logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`)
      await this.cleanCacheDirForPendingUpdate()
      return null
    }

I think this actually means that for some reason the update-info.json file that the cachedInfo object is supposed to draw from does not exist. Indeed I checked my directory and there is nothing.

When is this file supposed to be created?

What could be causing this?

Are there more logging steps that can be done?

b-zurg added a commit to b-zurg/electron-builder that referenced this issue May 5, 2020
Closes electron-userland#4928

This change is to remove the use of `==` in favour of `===` (i.e. remove all uses of abstract equality operator in favour of the strict equality operator)
@b-zurg b-zurg changed the title Invalid Cache Check is not Thorough Not Downloading Update Error - NSIS + AWS S3 May 5, 2020
@b-zurg b-zurg changed the title Not Downloading Update Error - NSIS + AWS S3 "TypeError: Cannot read property 'fileName' of undefined" when downloading May 5, 2020
@b-zurg b-zurg changed the title "TypeError: Cannot read property 'fileName' of undefined" when downloading No update-info.json file in update cache folder 😶 May 6, 2020
@b-zurg
Copy link
Contributor Author

b-zurg commented May 6, 2020

It seems that this file is supposed to be created normally in the update download process. I am unsure why it was not created in my case but I have a fix in the linked PR which will ensure that the update cache folder is cleared and recreated if the file does not exist.

I tested this locally and this fix does work and the cache folder created correctly.

Update

The root cause of this is fs-extra's readJson is not throwing as expected but rather succeeding and returning undefined. I think this could be because of a recent version or patch of node. Anyhow it seems unreliable to depend on an exception for an important code execution path. This clearing of the updater cache needs to happen on every initial installation's check for an update and is kind of critical.

This is the code in question

private async getValidCachedUpdateFile(fileInfo: ResolvedUpdateFileInfo, logger: Logger): Promise<string | null> {
let cachedInfo: CachedUpdateInfo
const updateInfoFile = this.getUpdateInfoFile()
try {
cachedInfo = await readJson(updateInfoFile)
}
catch (e) {
let message = `No cached update info available`
if (e.code !== "ENOENT") {
await this.cleanCacheDirForPendingUpdate()
message += ` (error on read: ${e.message})`
}
logger.info(message)
return null
}
if (cachedInfo.fileName == null) {
logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`)
await this.cleanCacheDirForPendingUpdate()
return null
}

The optional chaining and nullish coalescing changes I added before should fix things but I'm going to add an early return as well for clarity.

develar pushed a commit that referenced this issue May 14, 2020
* fix: cached update validation failing on undefined filename

Closes #4928

This change is to remove the use of `==` in favour of `===` (i.e. remove all uses of abstract equality operator in favour of the strict equality operator)

* fix: handle case where cachedInfo object is undefined

* fix: early return if update file does not exist
@spcBackToLife
Copy link

i meet the same problem with no update-info.json file . and the error is same:
image

electron: 8.3.2
electron-builder: 22.7.0

@spcBackToLife
Copy link

It seems that this file is supposed to be created normally in the update download process. I am unsure why it was not created in my case but I have a fix in the linked PR which will ensure that the update cache folder is cleared and recreated if the file does not exist.

I tested this locally and this fix does work and the cache folder created correctly.

Update

The root cause of this is fs-extra's readJson is not throwing as expected but rather succeeding and returning undefined. I think this could be because of a recent version or patch of node. Anyhow it seems unreliable to depend on an exception for an important code execution path. This clearing of the updater cache needs to happen on every initial installation's check for an update and is kind of critical.

This is the code in question

private async getValidCachedUpdateFile(fileInfo: ResolvedUpdateFileInfo, logger: Logger): Promise<string | null> {
let cachedInfo: CachedUpdateInfo
const updateInfoFile = this.getUpdateInfoFile()
try {
cachedInfo = await readJson(updateInfoFile)
}
catch (e) {
let message = `No cached update info available`
if (e.code !== "ENOENT") {
await this.cleanCacheDirForPendingUpdate()
message += ` (error on read: ${e.message})`
}
logger.info(message)
return null
}
if (cachedInfo.fileName == null) {
logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`)
await this.cleanCacheDirForPendingUpdate()
return null
}

The optional chaining and nullish coalescing changes I added before should fix things but I'm going to add an early return as well for clarity.

the problem is same:

@b-zurg
Copy link
Contributor Author

b-zurg commented Jul 6, 2020

Yeah my fix was incomplete. My project was actually having issues with fs-extra in other dependencies as well, and I think the suspect is my webpack configuration. I'm not really sure what was happening. I might give electron-builder another go soon and see if that was it, because according to the spec provided by fs-extra I think the code in electron-builder should be working.

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 a pull request may close this issue.

2 participants