How to use the builder-util-runtime.newError function in builder-util-runtime

To help you get started, we’ve selected a few builder-util-runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electron-userland / electron-builder / packages / electron-updater / src / differentialDownloader / DataSplitter.ts View on Github external
}

    while (true) {
      if (this.readState === ReadState.BODY) {
        this.readState = ReadState.INIT
      }
      else {
        this.partIndex++

        let taskIndex = this.partIndexToTaskIndex.get(this.partIndex)
        if (taskIndex == null) {
          if (this.isFinished) {
            taskIndex = this.options.end
          }
          else {
            throw newError("taskIndex is null", "ERR_DATA_SPLITTER_TASK_INDEX_IS_NULL")
          }
        }

        const prevTaskIndex = this.partIndex === 0 ? this.options.start : (this.partIndexToTaskIndex.get(this.partIndex - 1)!! + 1 /* prev part is download, next maybe copy */)
        if (prevTaskIndex < taskIndex) {
          await this.copyExistingData(prevTaskIndex, taskIndex)
        }
        else if (prevTaskIndex > taskIndex) {
          throw newError("prevTaskIndex must be < taskIndex", "ERR_DATA_SPLITTER_TASK_INDEX_ASSERT_FAILED")
        }

        if (this.isFinished) {
          this.onPartEnd()
          this.finishHandler()
          return
        }
github electron-userland / electron-builder / packages / electron-updater / src / providers / PrivateGitHubProvider.ts View on Github external
async getLatestVersion(): Promise {
    const cancellationToken = new CancellationToken()
    const channelFile = getChannelFilename(this.getDefaultChannelName())

    const releaseInfo = await this.getLatestVersionInfo(cancellationToken)
    const asset = releaseInfo.assets.find(it => it.name === channelFile)
    if (asset == null) {
      // html_url must be always, but just to be sure
      throw newError(`Cannot find ${channelFile} in the release ${releaseInfo.html_url || releaseInfo.name}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
    }

    const url = new URL(asset.url)
    let result: any
    try {
      result = safeLoad((await this.httpRequest(url, this.configureHeaders("application/octet-stream"), cancellationToken))!!)
    }
    catch (e) {
      if (e instanceof HttpError && e.statusCode === 404) {
        throw newError(`Cannot find ${channelFile} in the latest release artifacts (${url}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
      }
      throw e
    }

    (result as PrivateGitHubUpdateInfo).assets = releaseInfo.assets
    return result
github electron-userland / electron-builder / packages / electron-updater / src / differentialDownloader / DataSplitter.ts View on Github external
let taskIndex = this.partIndexToTaskIndex.get(this.partIndex)
        if (taskIndex == null) {
          if (this.isFinished) {
            taskIndex = this.options.end
          }
          else {
            throw newError("taskIndex is null", "ERR_DATA_SPLITTER_TASK_INDEX_IS_NULL")
          }
        }

        const prevTaskIndex = this.partIndex === 0 ? this.options.start : (this.partIndexToTaskIndex.get(this.partIndex - 1)!! + 1 /* prev part is download, next maybe copy */)
        if (prevTaskIndex < taskIndex) {
          await this.copyExistingData(prevTaskIndex, taskIndex)
        }
        else if (prevTaskIndex > taskIndex) {
          throw newError("prevTaskIndex must be < taskIndex", "ERR_DATA_SPLITTER_TASK_INDEX_ASSERT_FAILED")
        }

        if (this.isFinished) {
          this.onPartEnd()
          this.finishHandler()
          return
        }

        start = this.searchHeaderListEnd(chunk, start)

        if (start === -1) {
          this.readState = ReadState.HEADER
          return
        }
      }
github electron-userland / electron-builder / packages / electron-updater / src / differentialDownloader / DataSplitter.ts View on Github external
private async handleData(chunk: Buffer): Promise {
    let start = 0

    if (this.ignoreByteCount !== 0 && this.remainingPartDataCount !== 0) {
      throw newError("Internal error", "ERR_DATA_SPLITTER_BYTE_COUNT_MISMATCH")
    }

    if (this.ignoreByteCount > 0) {
      const toIgnore = Math.min(this.ignoreByteCount, chunk.length)
      this.ignoreByteCount -= toIgnore
      start = toIgnore
    }
    else if (this.remainingPartDataCount > 0) {
      const toRead = Math.min(this.remainingPartDataCount, chunk.length)
      this.remainingPartDataCount -= toRead
      await this.processPartData(chunk, 0, toRead)
      start = toRead
    }

    if (start === chunk.length) {
      return
github electron-userland / electron-builder / packages / electron-updater / src / providers / GitHubProvider.ts View on Github external
version = await this.getLatestVersionString(cancellationToken)
        for (const element of feed.getElements("entry")) {
          if (element.element("link").attribute("href").match(hrefRegExp)!![1] === version) {
            latestRelease = element
            break
          }
        }

      }
    }
    catch (e) {
      throw newError(`Cannot parse releases feed: ${e.stack || e.message},\nXML:\n${feedXml}`, "ERR_UPDATER_INVALID_RELEASE_FEED")
    }

    if (version == null) {
      throw newError(`No published versions on GitHub`, "ERR_UPDATER_NO_PUBLISHED_VERSIONS")
    }

    const channelFile = getChannelFilename(this.getDefaultChannelName())
    const channelFileUrl = newUrlFromBase(this.getBaseDownloadPath(version, channelFile), this.baseUrl)
    const requestOptions = this.createRequestOptions(channelFileUrl)
    let rawData: string
    try {
      rawData = (await this.executor.request(requestOptions, cancellationToken))!!
    }
    catch (e) {
      if (!this.updater.allowPrerelease && e instanceof HttpError && e.statusCode === 404) {
        throw newError(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
      }
      throw e
    }
github electron-userland / electron-builder / packages / electron-updater / src / differentialDownloader / DataSplitter.ts View on Github external
private onPartEnd() {
    const expectedLength = this.partIndexToLength[this.partIndex - 1]
    if (this.actualPartLength !== expectedLength) {
      throw newError(`Expected length: ${expectedLength} differs from actual: ${this.actualPartLength}`, "ERR_DATA_SPLITTER_LENGTH_MISMATCH")
    }
    this.actualPartLength = 0
  }
github electron-userland / electron-builder / packages / electron-updater / src / providers / GitHubProvider.ts View on Github external
}

    if (version == null) {
      throw newError(`No published versions on GitHub`, "ERR_UPDATER_NO_PUBLISHED_VERSIONS")
    }

    const channelFile = getChannelFilename(this.getDefaultChannelName())
    const channelFileUrl = newUrlFromBase(this.getBaseDownloadPath(version, channelFile), this.baseUrl)
    const requestOptions = this.createRequestOptions(channelFileUrl)
    let rawData: string
    try {
      rawData = (await this.executor.request(requestOptions, cancellationToken))!!
    }
    catch (e) {
      if (!this.updater.allowPrerelease && e instanceof HttpError && e.statusCode === 404) {
        throw newError(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
      }
      throw e
    }

    const result = parseUpdateInfo(rawData, channelFile, channelFileUrl)
    if (result.releaseName == null) {
      result.releaseName = latestRelease.elementValueOrEmpty("title")
    }

    if (result.releaseNotes == null) {
      result.releaseNotes = computeReleaseNotes(this.updater.currentVersion, this.updater.fullChangelog, feed, latestRelease)
    }
    return result
  }
github electron-userland / electron-builder / packages / electron-updater / src / providers / PrivateGitHubProvider.ts View on Github external
if (!allowPrerelease) {
      basePath = `${basePath}/latest`
    }

    const url = newUrlFromBase(basePath, this.baseUrl)
    try {
      const version = (JSON.parse((await this.httpRequest(url, this.configureHeaders("application/vnd.github.v3+json"), cancellationToken))!!))
      if (allowPrerelease) {
        return version.find((v: any) => v.prerelease) || version[0]
      }
      else {
        return version
      }
    }
    catch (e) {
      throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
    }
  }