babalae/better-genshin-impact · error · Exception

gridScreenName为空或错误

Error message

gridScreenName为空或错误

What it means

Exception thrown at line 283 when ScriptObjectConverter.GetValue for gridScreenName returns null — meaning either the gridScreenName key was absent from the config ScriptObject, or its value could not be coerced to the GridScreenName enum. The `?? throw` treats both as 'missing or wrong'. gridScreenName identifies which inventory grid layout to use for counting.

Source

Thrown at BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs:283

                        }
                    }

                    var autoEatConfig = TaskContext.Instance().Config.AutoEatConfig;
                    return await new AutoEatTask(new AutoEatParam()
                    {
                        CheckInterval = autoEatConfig.CheckInterval,
                        EatInterval = autoEatConfig.EatInterval,
                        ShowNotification = autoEatConfig.ShowNotification,
                        FoodName = foodName
                    }).Start(cancellationToken);
                }
            case "CountInventoryItem":
                {
                    if (soloTask.Config == null)
                    {
                        throw new NullReferenceException($"{nameof(soloTask.Config)}为空");
                    }
                    GridScreenName gridScreenName = ScriptObjectConverter.GetValue((ScriptObject)soloTask.Config, "gridScreenName", (GridScreenName?)null) ?? throw new Exception("gridScreenName为空或错误");
                    string? itemName = ScriptObjectConverter.GetValue((ScriptObject)soloTask.Config, "itemName", (string?)null);
                    IEnumerable<string>? itemNames = ScriptObjectConverter.GetValue<string>((ScriptObject)soloTask.Config, "itemNames");
                    CountInventoryItemParam param = new()
                    {
                        GridScreenName = gridScreenName,
                        ItemName = itemName,
                        ItemNames = itemNames?.ToList() ?? []
                    };

                    var result = await new CountInventoryItem(param).Start(cancellationToken);
                    if (param.ItemName != null)
                    {
                        return result;
                    }
                    else
                    {
                        dynamic expando = new ExpandoObject();
                        var expandoDict = (IDictionary<string, object>)expando;

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Always include gridScreenName in the CountInventoryItem config.
  2. Use a valid GridScreenName value — check the enum definition for accepted members.
  3. Log the raw config object when this fires to see exactly what was passed.

Example fix

// before (JS)
new SoloTask('CountInventoryItem', { itemName: 'Mora' }) // missing gridScreenName -> throws

// after (JS)
new SoloTask('CountInventoryItem', { gridScreenName: '5x10', itemName: 'Mora' })
Defensive patterns

Strategy: validation

Validate before calling

// JS side
if (!cfg.gridScreenName) throw new Error('gridScreenName is required for CountInventoryItem');

Prevention

When it happens

Trigger: Config object omits gridScreenName entirely. Config provides gridScreenName as an invalid string (typo, wrong casing) or an int that does not map to a GridScreenName member.

Common situations: Author forgot the gridScreenName field. Wrong grid name for the current game version. Casing mismatch (GridScreenName values are likely specific strings/enums).

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/eb24e67fe94e36ab. Report an issue: GitHub.