Bugfix: Unable to import from GCS is import data is missing object fields#2733
Bugfix: Unable to import from GCS is import data is missing object fields#2733rinickolous wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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 withimportData?.[key] ?? nulland add verbose debug logs when import data or keys are missing. - In
gurps-item.ts, defaultitemDatato an Equipment placeholder ingetDefaultArtworkwhen none is provided, removing theAnyObjectcast. - In
actor/data/character.ts, tighten_preCreate/_preUpdateoption types usingDocument.Database.*OptionsForName<'Actor'>and extract theitemsarray 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 againstimportDatabeing null/undefined. Now that the rest ofimportSchemaexplicitly handles missingimportData(viaimportData?.[key]), this unguarded access can throw when verbose mode is enabled and a recursive call (e.g. anArrayFieldelement via line 122/133) passes through anullitem. Consider guarding the unknown-keys check withif (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
| 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`) | ||
| } |
cc9dd0d to
a61586c
Compare
| 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`) |
There was a problem hiding this comment.
I agree that the check for importData is undefined/null should occur before it is used in the expression Object.keys(importData).
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
I agree with this comment.
Fixes #2719
Fixes #2709