Skip to content

Bugfix: Unable to import from GCS is import data is missing object fields#2733

Open
rinickolous wants to merge 1 commit into
develop/v13-onlyfrom
bugfix/2719
Open

Bugfix: Unable to import from GCS is import data is missing object fields#2733
rinickolous wants to merge 1 commit into
develop/v13-onlyfrom
bugfix/2719

Conversation

@rinickolous
Copy link
Copy Markdown
Collaborator

Fixes #2719
Fixes #2709

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes GCS import failures that occur when nested import objects/fields are missing (null/undefined), and adjusts a couple of related type/usage details. Previously, importSchema accessed importData[key] directly and threw on null containers (e.g. modifiers with no nested object); the fix safely defaults missing values and adds verbose diagnostics.

Changes:

  • In schema/base.ts, defensively read fields with importData?.[key] ?? null and add verbose debug logs when import data or keys are missing.
  • In gurps-item.ts, default itemData to an Equipment placeholder in getDefaultArtwork when none is provided, removing the AnyObject cast.
  • In actor/data/character.ts, tighten _preCreate/_preUpdate option types using Document.Database.*OptionsForName<'Actor'> and extract the items array to a local for clarity.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/module/importer/gcs-importer/schema/base.ts Tolerate missing importData/keys and emit verbose diagnostics during GCS import.
src/module/item/gurps-item.ts Provide a default item type when getDefaultArtwork is called without data.
src/module/actor/data/character.ts Switch to Document.Database.*OptionsForName<'Actor'> types; minor local-variable refactor.
Comments suppressed due to low confidence (1)

src/module/importer/gcs-importer/schema/base.ts:79

  • Object.keys(importData) on line 66 (just above this hunk) is not guarded against importData being null/undefined. Now that the rest of importSchema explicitly handles missing importData (via importData?.[key]), this unguarded access can throw when verbose mode is enabled and a recursive call (e.g. an ArrayField element via line 122/133) passes through a null item. Consider guarding the unknown-keys check with if (importData) as well.
      if (verbose) {
        if (!importData)
          console.debug(`[GCS Import: ${this.name}] No import data provided, using default values for all fields`)
        else if (importData[key] === undefined)
          console.debug(`[GCS Import: ${this.name}] Key '${key}' is missing from import data, using default value`)
      }

      const value = importData?.[key] ?? null

Comment on lines +72 to +77
if (verbose) {
if (!importData)
console.debug(`[GCS Import: ${this.name}] No import data provided, using default values for all fields`)
else if (importData[key] === undefined)
console.debug(`[GCS Import: ${this.name}] Key '${key}' is missing from import data, using default value`)
}
@rinickolous rinickolous force-pushed the bugfix/2719 branch 2 times, most recently from cc9dd0d to a61586c Compare May 16, 2026 16:13
@rinickolous rinickolous changed the base branch from develop/v13-only to bugfix/2734 May 16, 2026 16:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment on lines 64 to +71
if (verbose) {
const schemaKeys = new Set(Object.keys(schema))
const unknownKeys = Object.keys(importData).filter(key => !schemaKeys.has(key) && key !== 'replacements')

if (unknownKeys.length) console.debug(`[GCS Import: ${this.name}] Unknown data keys:`, unknownKeys)

if (!importData)
console.debug(`[GCS Import: ${this.name}] No import data provided, using default values for all fields`)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree that the check for importData is undefined/null should occur before it is used in the expression Object.keys(importData).

Comment on lines +74 to 85
if (importData) {
for (const [key, field] of Object.entries(schema)) {
if (verbose) {
if (importData[key] === undefined)
console.debug(`[GCS Import: ${this.name}] Key '${key}' is missing from import data, using default value`)
}

const value = importData?.[key] ?? null

data[key] = this._importField(value, field, key, replacements, verbose)
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree with this comment.

Base automatically changed from bugfix/2734 to develop/v13-only May 29, 2026 20:04
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.

V1.0.0 error on GCS character import V1.0.0 Importing GCS equipment library fails

3 participants