chore: clean up debug statements in preparation for 10.0 release, add debug docs (#21621)

Co-authored-by: Muaz Othman <muazweb@gmail.com>
This commit is contained in:
Zach Bloomquist
2022-05-25 13:40:04 -04:00
committed by GitHub
parent 06948c4691
commit 3c0c864fa9
21 changed files with 135 additions and 125 deletions
+3 -26
View File
@@ -329,9 +329,7 @@ This will install all the dependencies for the repo and perform a preliminary bu
yarn start
```
If there are errors building the packages, prefix the commands with `DEBUG=cypress:*` to see more details.
This outputs a lot of debugging lines. To focus on an individual module, run with `DEBUG=cypress:launcher` for instance.
If there are errors building the packages, prefix the commands with `DEBUG=cypress:*` to see more details. This outputs a lot of debugging lines. To focus on an individual module, run with `DEBUG=cypress:launcher:*` for instance. See ["Debug logs"](./guides/debug-logs.md) for more info.
When running `yarn start` this routes through the CLI and eventually calls `yarn dev` with the proper arguments. This enables Cypress day-to-day development to match the logic of the built binary + CLI integration.
@@ -411,30 +409,9 @@ Each package is responsible for building itself and testing itself and can do so
| `test-integration` | Run all integration tests within the package; `exit 0` if N/A |
| `test-watch` | Run all unit tests in the package in watch mode |
#### Debugging
#### Debug Logs
Some packages use [debug](https://github.com/visionmedia/debug#readme) to
log debug messages to the console. The naming scheme should be
`cypress:<package name>`; where package name is without the `@packages` scope. For example to see launcher messages during unit
tests start it using
```bash
$ DEBUG=cypress:launcher yarn test --scope @packages/launcher
```
If you want to see log messages from all Cypress projects use wild card
```bash
$ DEBUG=cypress:*
```
Or for an individual package:
```bash
DEBUG=cypress:cli
DEBUG=cypress:server
DEBUG=cypress:launcher
```
Many Cypress packages print out debugging information to console via the `debug` module. See ["Debug logs"](./guides/debug-logs.md) for more information.
### Coding Style
+6 -2
View File
@@ -10,11 +10,15 @@ For general contributor information, check out [`CONTRIBUTING.md`](../CONTRIBUTI
## Table of Contents
* [App lifecycle](./app-lifecycle.md)
* [Building release artifacts](./building-release-artifacts.md)
* [Code signing](./code-signing.md)
* [Debug logs](./debug-logs.md)
* [Determining the next version of Cypress to be released](./next-version.md)
* [Remaining Platform Agnostic](./remaining-platform-agnostic.md)
* [E2E Open Mode Testing](./e2e-open-testing.md)
* [Error handling](./error-handling.md)
* [Patching packages](./patch-package.md)
* [Release process](./release-process.md)
* [Testing other projects](./testing-other-projects.md)
* [Testing other projects](./testing-other-projects.md)
* [Testing strategy and style guide (draft)](./testing-strategy-and-styleguide.md)
* [Writing cross-platform JavaScript](./writing-cross-platform-javascript.md)
+42
View File
@@ -0,0 +1,42 @@
# Debug Logs
Many Cypress packages use the [`debug` module][debug] to log runtime info to the console.
## Choosing a namespace
The naming scheme for debug namespaces should generally follow this pattern:
```
cypress:{packageName}:{relative path to file from src root, using : to separate directories, minus index if applicable}
# examples:
# packages/server/lib/util/file.js -> cypress:server:util:file
# packages/launcher/windows/index.ts -> cypress:launcher:windows
```
`cypress-verbose` can be used instead of `cypress` if the logs are overly verbose and would make the output of `DEBUG=cypress:*` unreadable.
Exceptions to these rules:
* The `cli` uses `cypress:cli:*`.
* NPM packages should use `{moduleName}` as a prefix instead of `cypress`, like `cypress-webpack-preprocessor` for `npm/webpack-preprocessor`.
* In some places, like per-request in the `proxy` package, it's more useful to attach `debug` messages to something besides the module (like individual HTTP requests). In that case, it's okay to create namespaces as you see fit. But at least begin with `cypress:{packageName}` or `cypress-verbose:{packageName}`
## Using debug logs
Pass the `DEBUG` environment variable to select a set of logs to print to `stderr`. Example selectors:
```shell
# frequently useful to get a sense of what is happening in the app at a high level
DEBUG=cypress:*
# print all info and verbose logs, but don't print verbose logs from `some-noisy-package`
DEBUG=cypress:*,cypress-verbose:*,-cypress-verbose:some-noisy-package:*
# print out verbose per-request data for proxied HTTP requests
DEBUG=cypress-verbose:proxy:http
# in the browser, set `localStorage.DEBUG`:
localStorage.DEBUG = 'cypress:driver,cypress:driver:*'
```
For more info, see the [public documentation for printing debug logs](https://docs.cypress.io/guides/references/troubleshooting#Print-DEBUG-logs) and the [`debug` module docs][debug]
[debug]: https://github.com/visionmedia/debug#readme
+2 -2
View File
@@ -16,7 +16,7 @@ export {
BreakingOptionErrorKey,
}
const debug = Debug('cypress:config:validator')
const debug = Debug('cypress:config:browser')
const dashesOrUnderscoresRe = /^(_-)+/
@@ -134,7 +134,7 @@ export const matchesConfigKey = (key: string) => {
}
export const validate = (cfg: any, onErr: (property: string) => void) => {
debug('validating configuration', cfg)
debug('validating configuration')
return _.each(cfg, (value, key) => {
const validationFn = validationRules[key]
@@ -235,7 +235,7 @@ export class ProjectConfigIpc extends EventEmitter {
.value()
}
debug('fork child process', CHILD_PROCESS_FILE_PATH, configProcessArgs, _.omit(childOptions, 'env'))
debug('fork child process %o', { CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions: _.omit(childOptions, 'env') })
const proc = fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions)
@@ -27,7 +27,7 @@ import { pathToArray } from 'graphql/jsutils/Path'
export type CloudDataResponse = ExecutionResult & Partial<OperationResult> & { executing?: Promise<ExecutionResult & Partial<OperationResult>> }
const debug = debugLib('cypress:data-context:CloudDataSource')
const debug = debugLib('cypress:data-context:sources:CloudDataSource')
const cloudEnv = getenv('CYPRESS_INTERNAL_CLOUD_ENV', process.env.CYPRESS_INTERNAL_ENV || 'development') as keyof typeof REMOTE_SCHEMA_URLS
const REMOTE_SCHEMA_URLS = {
@@ -10,8 +10,8 @@ import type { gitStatusType } from '@packages/types'
import chokidar from 'chokidar'
import _ from 'lodash'
const debug = Debug('cypress:data-context:GitDataSource')
const debugVerbose = Debug('cypress-verbose:data-context:GitDataSource')
const debug = Debug('cypress:data-context:sources:GitDataSource')
const debugVerbose = Debug('cypress-verbose:data-context:sources:GitDataSource')
dayjs.extend(relativeTime)
@@ -238,7 +238,7 @@ export class GitDataSource {
this.#git.status(),
])
debug('stdout %s', stdout)
debugVerbose('stdout %s', stdout.toString())
const changed: string[] = []
@@ -292,12 +292,12 @@ export class GitDataSource {
this.#gitMeta.set(file, toSet)
if (!_.isEqual(toSet, current)) {
debug(`updated %s %o`, file, toSet)
changed.push(file)
}
}
if (!this.#destroyed) {
debugVerbose(`updated %o`, changed)
this.config.onGitInfoChange(changed)
}
} catch (e) {
@@ -326,16 +326,14 @@ export class GitDataSource {
const stdout = result.stdout.split('\n')
if (result.exitCode !== 0) {
debug(`error... stderr`, result.stderr)
debug(`command execution error: %o`, result)
}
if (stdout.length !== absolutePaths.length) {
debug('error... stdout:', stdout)
debug('unexpected command execution result: %o', result)
throw Error(`Expect result array to have same length as input. Input: ${absolutePaths.length} Output: ${stdout.length}`)
}
debug('stdout for git info', stdout)
return stdout
}
@@ -5,7 +5,7 @@ import type { core } from 'nexus'
import type { DataContext } from '..'
import { DocumentNodeBuilder } from '../util/DocumentNodeBuilder'
const debug = debugLib('cypress:data-context:GraphQLDataSource')
const debug = debugLib('cypress:data-context:sources:GraphQLDataSource')
const RESOLVED_SOURCE = Symbol('RESOLVED_SOURCE')
export interface PushResultParams {
@@ -12,7 +12,7 @@ import parseGlob from 'parse-glob'
import micromatch from 'micromatch'
import RandExp from 'randexp'
const debug = Debug('cypress:data-context')
const debug = Debug('cypress:data-context:sources:ProjectDataSource')
import assert from 'assert'
import type { DataContext } from '..'
@@ -3,7 +3,7 @@ import type { DataContext } from '..'
import type { TestingType } from '@packages/types'
import Debug from 'debug'
const debug = Debug('cypress:data-context:versions-data-source')
const debug = Debug('cypress:data-context:sources:VersionsDataSource')
const pkg = require('@packages/root')
const nmi = require('node-machine-id')
@@ -124,7 +124,7 @@ export class VersionsDataSource {
const responseJson = await response.json() as { time: Record<string, string>}
debug('NPM release dates %o', responseJson.time)
debug('NPM release dates received %o', { modified: responseJson.time.modified })
return responseJson.time
}
+2 -1
View File
@@ -30,6 +30,7 @@ Uses [debug](https://github.com/visionmedia/debug#readme)
to output debug log messages. To turn on, use
```sh
DEBUG=cypress:launcher yarn workspace @packages/launcher test
DEBUG=cypress:launcher:* yarn workspace @packages/launcher test
```
Verbose messages, including detailed stdout, are available under `cypress-verbose:launcher:*`.
+8 -6
View File
@@ -1,8 +1,10 @@
import { log } from './log'
import Debug from 'debug'
import * as cp from 'child_process'
import { browsers, FoundBrowser } from '@packages/types'
import type { Readable } from 'stream'
export const debug = Debug('cypress:launcher:browsers')
export { browsers }
/** list of the browsers we can detect and use by default */
@@ -18,7 +20,7 @@ export function launch (
args: string[] = [],
defaultBrowserEnv = {},
): LaunchedBrowser {
log('launching browser %o', { browser, url })
debug('launching browser %o', { browser, url })
if (!browser.path) {
throw new Error(`Browser ${browser.name} is missing path`)
@@ -28,7 +30,7 @@ export function launch (
args = [url].concat(args)
}
log('spawning browser with args %o', { args })
debug('spawning browser with args %o', { args })
// allow setting default env vars such as MOZ_HEADLESS_WIDTH
// but only if it's not already set by the environment
@@ -37,15 +39,15 @@ export function launch (
const proc = cp.spawn(browser.path, args, { stdio: ['ignore', 'pipe', 'pipe'], env })
proc.stdout.on('data', (buf) => {
log('%s stdout: %s', browser.name, String(buf).trim())
debug('%s stdout: %s', browser.name, String(buf).trim())
})
proc.stderr.on('data', (buf) => {
log('%s stderr: %s', browser.name, String(buf).trim())
debug('%s stderr: %s', browser.name, String(buf).trim())
})
proc.on('exit', (code, signal) => {
log('%s exited: %o', browser.name, { code, signal })
debug('%s exited: %o', browser.name, { code, signal })
})
return proc
+6 -5
View File
@@ -1,9 +1,11 @@
import { findApp, FindAppParams } from './util'
import type { Browser, DetectedBrowser } from '@packages/types'
import * as linuxHelper from '../linux'
import { log } from '../log'
import Debug from 'debug'
import { get } from 'lodash'
const debugVerbose = Debug('cypress-verbose:launcher:darwin')
type Detectors = {
[name: string]: {
[channel: string]: FindAppParams
@@ -98,16 +100,15 @@ export function detect (browser: Browser): Promise<DetectedBrowser> {
if (!findAppParams) {
// ok, maybe it is custom alias?
log('detecting custom browser %s on darwin', browser.name)
debugVerbose('could not find %s in findApp map, falling back to linux detection method', browser.name)
return linuxHelper.detect(browser)
}
return findApp(findAppParams)
.then((val) => ({ name: browser.name, ...val }))
.catch(() => {
log('could not detect %s using traditional Mac methods', browser.name)
log('trying linux search')
.catch((err) => {
debugVerbose('could not detect %s using findApp %o, falling back to linux detection method', browser.name, err)
return linuxHelper.detect(browser)
})
+11 -9
View File
@@ -1,21 +1,23 @@
import { log } from '../log'
import Debug from 'debug'
import { notInstalledErr } from '../errors'
import { utils } from '../utils'
import * as fs from 'fs-extra'
import * as path from 'path'
import * as plist from 'plist'
const debugVerbose = Debug('cypress-verbose:launcher:darwin:util')
/** parses Info.plist file from given application and returns a property */
export function parsePlist (p: string, property: string): Promise<string> {
const pl = path.join(p, 'Contents', 'Info.plist')
log('reading property file "%s"', pl)
debugVerbose('reading property file "%s"', pl)
const failed = (e: Error) => {
const msg = `Info.plist not found: ${pl}
${e.message}`
log('could not read Info.plist %o', { pl, e })
debugVerbose('could not read Info.plist %o', { pl, e })
throw notInstalledErr('', msg)
}
@@ -31,16 +33,16 @@ export function parsePlist (p: string, property: string): Promise<string> {
export function mdfind (id: string): Promise<string> {
const cmd = `mdfind 'kMDItemCFBundleIdentifier=="${id}"' | head -1`
log('looking for bundle id %s using command: %s', id, cmd)
debugVerbose('looking for bundle id %s using command: %s', id, cmd)
const logFound = (str: string) => {
log('found %s at %s', id, str)
debugVerbose('found %s at %s', id, str)
return str
}
const failedToFind = () => {
log('could not find %s', id)
debugVerbose('could not find %s', id)
throw notInstalledErr(id)
}
@@ -74,11 +76,11 @@ function formApplicationPath (appName: string) {
/** finds an application and its version */
export function findApp ({ appName, executable, appId, versionProperty }: FindAppParams): Promise<AppInfo> {
log('looking for app %s id %s', executable, appId)
debugVerbose('looking for app %s id %s', executable, appId)
const findVersion = (foundPath: string) => {
return parsePlist(foundPath, versionProperty).then((version) => {
log('got plist: %o', { foundPath, version })
debugVerbose('got plist: %o', { foundPath, version })
return {
path: path.join(foundPath, executable),
@@ -94,7 +96,7 @@ export function findApp ({ appName, executable, appId, versionProperty }: FindAp
const tryFullApplicationFind = () => {
const applicationPath = formApplicationPath(appName)
log('looking for application %s', applicationPath)
debugVerbose('looking for application %s', applicationPath)
return findVersion(applicationPath)
}
+6 -23
View File
@@ -5,7 +5,7 @@ import { browsers } from './browsers'
import * as darwinHelper from './darwin'
import { notDetectedAtPathErr } from './errors'
import * as linuxHelper from './linux'
import { log } from './log'
import Debug from 'debug'
import type {
Browser,
DetectedBrowser,
@@ -17,6 +17,9 @@ import type {
} from './types'
import * as windowsHelper from './windows'
const debug = Debug('cypress:launcher:detect')
const debugVerbose = Debug('cypress-verbose:launcher:detect')
type HasVersion = Omit<Partial<FoundBrowser>, 'version' | 'name'> & {
version: string
name: string
@@ -28,14 +31,6 @@ export const setMajorVersion = <T extends HasVersion>(browser: T): T => {
const unsupportedVersion = browser.minSupportedVersion && majorVersion < browser.minSupportedVersion
log(
'browser %s version %s major version %s',
browser.name,
browser.version,
majorVersion,
unsupportedVersion,
)
const foundBrowser = extend({}, browser, { majorVersion })
if (unsupportedVersion) {
@@ -77,7 +72,6 @@ function lookup (
platform: NodeJS.Platform,
browser: Browser,
): Promise<DetectedBrowser> {
log('looking up %s on %s platform', browser.name, platform)
const helper = getHelper(platform)
if (!helper) {
@@ -120,13 +114,9 @@ function checkOneBrowser (browser: Browser): Promise<boolean | HasVersion> {
'unsupportedVersion',
] as const
const logBrowser = (props: any) => {
log('setting major version for %j', props)
}
const failed = (err: NotInstalledError) => {
if (err.notInstalled) {
log('browser %s not installed', browser.name)
debugVerbose('browser %s not installed', browser.name)
return false
}
@@ -134,16 +124,9 @@ function checkOneBrowser (browser: Browser): Promise<boolean | HasVersion> {
throw err
}
log('checking one browser %s', browser.name)
return lookup(platform, browser)
.then((val) => ({ ...browser, ...val }))
.then((val) => _.pick(val, pickBrowserProps) as HasVersion)
.then((val) => {
logBrowser(val)
return val
})
.then((browser) => setMajorVersion(browser))
.catch(failed)
}
@@ -165,7 +148,7 @@ export const detect = (goalBrowsers?: Browser[]): Bluebird<FoundBrowser[]> => {
return compact(browsers) as FoundBrowser[]
}
log('detecting if the following browsers are present %o', goalBrowsers)
debug('detecting if the following browsers are present %o', goalBrowsers)
return Bluebird.mapSeries(goalBrowsers, checkBrowser)
.then((val) => _.flatten(val))
+11 -8
View File
@@ -1,4 +1,4 @@
import { log } from '../log'
import Debug from 'debug'
import type { FoundBrowser, Browser } from '@packages/types'
import type { PathData } from '../types'
import { notInstalledErr } from '../errors'
@@ -9,6 +9,9 @@ import path from 'path'
import Bluebird from 'bluebird'
import which from 'which'
const debug = Debug('cypress:launcher:linux')
const debugVerbose = Debug('cypress-verbose:launcher:linux')
async function isFirefoxSnap (binary: string): Promise<boolean> {
try {
return await Bluebird.resolve((async () => {
@@ -29,7 +32,7 @@ async function isFirefoxSnap (binary: string): Promise<boolean> {
})())
.timeout(30000)
} catch (err) {
log('failed to check if Firefox is a snap, assuming it isn\'t %o', { err, binary })
debug('failed to check if Firefox is a snap, assuming it isn\'t %o', { err, binary })
return false
}
@@ -52,7 +55,7 @@ function getLinuxBrowser (
return m[1]
}
log(
debug(
'Could not extract version from stdout using regex: %o', {
stdout,
versionRegex,
@@ -63,7 +66,7 @@ function getLinuxBrowser (
}
const logAndThrowError = (err: Error) => {
log(
debugVerbose(
'Received error detecting browser binary: "%s" with error:',
binary,
err.message,
@@ -78,7 +81,7 @@ function getLinuxBrowser (
if (name === 'chromium' && versionString.endsWith('snap')) {
// when running as a snap, chromium can only write to certain directories
// @see https://github.com/cypress-io/cypress/issues/7020
log('chromium is running as a snap, changing profile path')
debug('chromium is running as a snap, changing profile path')
foundBrowser.profilePath = path.join(os.homedir(), 'snap', 'chromium', 'current')
return
@@ -87,7 +90,7 @@ function getLinuxBrowser (
if (name === 'firefox' && (await isFirefoxSnap(binary))) {
// if the binary in the path points to a script that calls the snap, set a snap-specific profile path
// @see https://github.com/cypress-io/cypress/issues/19793
log('firefox is running as a snap, changing profile path')
debug('firefox is running as a snap, changing profile path')
foundBrowser.profilePath = path.join(os.homedir(), 'snap', 'firefox', 'current')
return
@@ -106,14 +109,14 @@ function getLinuxBrowser (
}
export function getVersionString (path: string) {
log('finding version string using command "%s --version"', path)
debugVerbose('finding version string using command "%s --version"', path)
return Bluebird.resolve(utils.getOutput(path, ['--version']))
.timeout(30000, `Timed out after 30 seconds getting browser version for ${path}`)
.then((val) => val.stdout)
.then((val) => val.trim())
.then((val) => {
log('stdout: %s', val)
debugVerbose('stdout for "%s --version": %s', path, val)
return val
})
-3
View File
@@ -1,3 +0,0 @@
import debug from 'debug'
export const log = debug('cypress:launcher')
+8 -5
View File
@@ -4,10 +4,13 @@ import os from 'os'
import { join, normalize, win32 } from 'path'
import { get } from 'lodash'
import { notInstalledErr } from '../errors'
import { log } from '../log'
import Debug from 'debug'
import type { PathData } from '../types'
import type { Browser, FoundBrowser } from '@packages/types'
const debug = Debug('cypress:launcher:windows')
const debugVerbose = Debug('cypress-verbose:launcher:windows')
function formFullAppPath (name: string) {
return [
`C:/Program Files (x86)/Google/Chrome/Application/${name}.exe`,
@@ -115,7 +118,7 @@ function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
const exePaths = formFullAppPathFn(browser.name)
log('looking at possible paths... %o', { browser, exePaths })
debugVerbose('looking at possible paths... %o', { browser, exePaths })
// shift and try paths 1-by-1 until we find one that works
const tryNextExePath = async () => {
@@ -130,7 +133,7 @@ function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
return fse.pathExists(path)
.then((exists) => {
log('found %s ?', path, exists)
debugVerbose('found %s ? %o', path, { exists })
if (!exists) {
return tryNextExePath()
@@ -139,7 +142,7 @@ function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
// Use exports.getVersionString here, rather than our local reference
// to that variable so that the tests can easily mock it
return exports.getVersionString(path).then((version) => {
log('browser %s at \'%s\' version %s', browser.name, exePath, version)
debug('got version string for %s: %o', browser.name, { exePath, version })
return {
name: browser.name,
@@ -149,7 +152,7 @@ function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
})
})
.catch((err) => {
log('error while looking up exe, trying next exePath %o', { exePath, exePaths, err })
debug('error while looking up exe, trying next exePath %o', { exePath, exePaths, err })
return tryNextExePath()
})
+2 -3
View File
@@ -5,12 +5,11 @@ import Debug from 'debug'
import getPort from 'get-port'
import path from 'path'
import urlUtil from 'url'
import { launch, LaunchedBrowser } from '@packages/launcher/lib/browsers'
import { debug as launcherDebug, launch, LaunchedBrowser } from '@packages/launcher/lib/browsers'
import FirefoxProfile from 'firefox-profile'
import * as errors from '../errors'
import firefoxUtil from './firefox-util'
import utils from './utils'
import * as launcherDebug from '@packages/launcher/lib/log'
import type { Browser, BrowserInstance } from './types'
import { EventEmitter } from 'events'
import os from 'os'
@@ -303,7 +302,7 @@ const defaultPreferences = {
'media.devices.insecure.enabled': true,
'media.getusermedia.insecure.enabled': true,
'marionette.log.level': launcherDebug.log.enabled ? 'Debug' : undefined,
'marionette.log.level': launcherDebug.enabled ? 'Debug' : undefined,
// where to download files
// 0: desktop
+1 -3
View File
@@ -13,7 +13,7 @@ export const osFileSystemExplorer = {
linux: 'File System',
} as const
const debug = debugModule('cypress:server:editors')
const debug = debugModule('cypress:server:util:editors')
const createEditor = (editor: Editor): Editor => {
return {
@@ -43,8 +43,6 @@ const computerOpener = (): Editor => {
const getUserEditors = async (): Promise<Editor[]> => {
return Bluebird.filter(getEnvEditors(), (editor) => {
debug('check if user has editor %s with binary %s', editor.name, editor.binary)
return shell.commandExists(editor.binary)
})
.then((editors: Editor[] = []) => {
+15 -15
View File
@@ -2,7 +2,7 @@ const _ = require('lodash')
const os = require('os')
const md5 = require('md5')
const path = require('path')
const debug = require('debug')('cypress:server:file')
const debugVerbose = require('debug')('cypress-verbose:server:util:file')
const Promise = require('bluebird')
const lockFile = Promise.promisifyAll(require('lockfile'))
const { fs } = require('./fs')
@@ -57,7 +57,7 @@ class File {
}
transaction (fn) {
debug('transaction for %s', this.path)
debugVerbose('transaction for %s', this.path)
return this._addToQueue(() => {
return fn({
@@ -68,19 +68,19 @@ class File {
}
get (...args) {
debug('get values from %s', this.path)
debugVerbose('get values from %s', this.path)
return this._get(false, ...args)
}
set (...args) {
debug('set values in %s', this.path)
debugVerbose('set values in %s', this.path)
return this._set(false, ...args)
}
remove () {
debug('remove %s', this.path)
debugVerbose('remove %s', this.path)
this._cache = {}
return this._lock()
@@ -88,7 +88,7 @@ class File {
return fs.removeAsync(this.path)
})
.finally(() => {
debug('remove succeeded or failed for %s', this.path)
debugVerbose('remove succeeded or failed for %s', this.path)
return this._unlock()
})
@@ -134,7 +134,7 @@ class File {
_read () {
return this._lock()
.then(() => {
debug('read %s', this.path)
debugVerbose('read %s', this.path)
return fs.readJsonAsync(this.path, 'utf8')
})
@@ -151,7 +151,7 @@ class File {
throw err
})
.finally(() => {
debug('read succeeded or failed for %s', this.path)
debugVerbose('read succeeded or failed for %s', this.path)
return this._unlock()
})
@@ -206,19 +206,19 @@ class File {
_write () {
return this._lock()
.then(() => {
debug('write %s', this.path)
debugVerbose('write %s', this.path)
return fs.outputJsonAsync(this.path, this._cache, { spaces: 2 })
})
.finally(() => {
debug('write succeeded or failed for %s', this.path)
debugVerbose('write succeeded or failed for %s', this.path)
return this._unlock()
})
}
_lock () {
debug('attempt to get lock on %s', this.path)
debugVerbose('attempt to get lock on %s', this.path)
return fs
.ensureDirAsync(this._lockFileDir)
@@ -227,21 +227,21 @@ class File {
return lockFile.lockAsync(this._lockFilePath, { wait: LOCK_TIMEOUT })
})
.finally(() => {
return debug('getting lock succeeded or failed for %s', this.path)
return debugVerbose('getting lock succeeded or failed for %s', this.path)
})
}
_unlock () {
debug('attempt to unlock %s', this.path)
debugVerbose('attempt to unlock %s', this.path)
return lockFile
.unlockAsync(this._lockFilePath)
.timeout(env.get('FILE_UNLOCK_TIMEOUT') || LOCK_TIMEOUT)
.catch(Promise.TimeoutError, () => { // ignore timeouts
debug(`unlock timeout error for %s`, this._lockFilePath)
debugVerbose(`unlock timeout error for %s`, this._lockFilePath)
})
.finally(() => {
return debug('unlock succeeded or failed for %s', this.path)
return debugVerbose('unlock succeeded or failed for %s', this.path)
})
}
}