docmirror/dev-sidecar · warning

newConfig 为空,不做任何操作

Error message

newConfig 为空,不做任何操作

What it means

Warning logged by the set(newConfig) API in config-api.js when it is called with null or undefined. Instead of crashing, the function short-circuits and returns the current configTarget unchanged — no config is loaded or applied. It is a defensive no-op guard.

Source

Thrown at packages/core/src/config-api.js:194

    }
  },
  doMerge: mergeApi.doMerge,
  doDiff: mergeApi.doDiff,
  /**
   * 读取 config.json 后,合并配置
   */
  reload () {
    const userConfig = configLoader.getUserConfig()
    return configApi.set(userConfig) || {}
  },
  update (partConfig) {
    const newConfig = lodash.merge(configApi.get(), partConfig)
    configApi.save(newConfig)
  },
  get,
  set (newConfig) {
    if (newConfig == null) {
      log.warn('newConfig 为空,不做任何操作')
      return configTarget
    }
    return configApi.load(newConfig)
  },
  load (newConfig) {
    const config = configLoader.getConfigFromFiles(newConfig, defConfig)
    configTarget = config
    return config
  },
  cloneDefault () {
    return lodash.cloneDeep(defConfig)
  },
  addDefault (key, defValue) {
    lodash.set(defConfig, key, defValue)
  },
  // 移除用户配置,用于恢复出厂设置功能
  async removeUserConfig () {
    const configPath = configLoader.getUserConfigPath()

View on GitHub (pinned to 7710cd56cc)

Solutions

  1. Ensure the caller builds a real config object before calling set() (e.g. pass {} instead of null to load defaults).
  2. If reading config from disk, fall back to {} when the file is missing/empty before calling set().
  3. Check upstream logic that computes the diff/override passed to set() and fix the null source.
  4. If null is intentional as a no-op, ignore the warning — behavior is safe and current config is returned.

Example fix

// before
const part = readUserOverride(); // may be null
DevSidecar.config.set(part)
// after
const part = readUserOverride() || {}
DevSidecar.config.set(part)
Defensive patterns

Strategy: type-guard

Validate before calling

if (newConfig == null) {
  console.warn('config is null, skipping set()')
  return
}
DevSidecar.config.set(newConfig)

Type guard

function isConfigObject(v) {
  return v != null && typeof v === 'object' && !Array.isArray(v)
}

Prevention

When it happens

Trigger: Calling DevSidecar.config.set(null) or set(undefined) directly, or indirectly when configApi.save(diffConfig) produced a null/undefined diff (e.g. new config equals defaults and merge logic yields null) that is then passed back through set.

Common situations: GUI/CLI code that reads a persisted user override from ~/.dev-sidecar/config.json which is missing or empty and passes the result straight to set(); plugin code passing an optional config object that was never initialized; refactored callers that no longer build the partConfig before merging.

Related errors


AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31). Data as JSON: /api/errors/1654579be5d1d31e. Report an issue: GitHub.