{"record":{"id":"ab362660487ec41d","repo":"lobehub/lobehub","slug":"datasets-datasetindex-fields-fieldindex-is","errorCode":null,"errorMessage":"datasets[${datasetIndex}].fields[${fieldIndex}] is invalid","messagePattern":"datasets\\[(.+?)\\]\\.fields\\[(.+?)\\] is invalid","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/commands/verifyHelpers.ts","lineNumber":323,"sourceCode":"    return undefined;\n  if (!Array.isArray(input.datasets) || !Array.isArray(input.visualizations)) {\n    throw new Error('datasets and visualizations must both be arrays');\n  }\n\n  let rowCount = 0;\n  const datasets = input.datasets.map((rawDataset, datasetIndex) => {\n    const dataset = objectValue(rawDataset);\n    const id = firstString(dataset?.id);\n    if (!id || !Array.isArray(dataset?.fields) || !Array.isArray(dataset.rows)) {\n      throw new Error(`datasets[${datasetIndex}] needs id, fields, and rows`);\n    }\n\n    const fields = dataset.fields.map((rawField, fieldIndex) => {\n      const field = objectValue(rawField);\n      const key = firstString(field?.key);\n      const type = field?.type;\n      if (!key || typeof type !== 'string' || !VISUALIZATION_FIELD_TYPES.has(type)) {\n        throw new Error(`datasets[${datasetIndex}].fields[${fieldIndex}] is invalid`);\n      }\n      return {\n        key,\n        label: firstString(field.label),\n        type,\n        unit: firstString(field.unit),\n      } as VerifyVisualizationField;\n    });\n    const fieldKeys = new Set(fields.map((field) => field.key));\n    if (fieldKeys.size !== fields.length) {\n      throw new Error(`datasets[${datasetIndex}] field keys must be unique`);\n    }\n\n    const rows = dataset.rows.map((rawRow, rowIndex) => {\n      const row = objectValue(rawRow);\n      if (\n        !row ||\n        Object.entries(row).some(([key, cell]) => !fieldKeys.has(key) || !visualizationValue(cell))","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/lobehub/lobehub/blob/10f24d7ade75139093a9373b364f6bc91f3cd7db/apps/cli/src/commands/verifyHelpers.ts#L305-L341","documentation":"Thrown while mapping dataset.fields when a field descriptor is invalid: key missing/empty/non-string, type not a string, or type not in the allowed set {boolean, category, number, string, temporal}. The allowed set is the VISUALIZATION_FIELD_TYPES whitelist that the report viewer knows how to render.","triggerScenarios":"datasets[i].fields[j] has no key, a numeric type, or a type like 'int'/'float'/'datetime' not in the whitelist.","commonSituations":"Author writes type: 'integer' instead of 'number'; type: 'date' instead of 'temporal'; key omitted because the field was auto-generated.","solutions":["Set field.type to one of: boolean, category, number, string, temporal.","Provide a non-empty string field.key.","Map common aliases: integer/float/double → number; date/datetime/timestamp → temporal; enum → category."],"exampleFix":"// before\n{ key: 'age', type: 'integer' }\n// after\n{ key: 'age', type: 'number' }","handlingStrategy":"validation","validationCode":"const FIELD_TYPES = new Set(['boolean','category','number','string','temporal']);\nfunction validField(f: unknown): boolean {\n  return !!f && typeof f === 'object' && typeof (f as any).key === 'string' && (f as any).key.length > 0 && typeof (f as any).type === 'string' && FIELD_TYPES.has((f as any).type);\n}","typeGuard":"function isFieldDescriptor(v: unknown): v is { key: string; type: 'boolean'|'category'|'number'|'string'|'temporal' } {\n  return !!v && typeof v === 'object' && typeof (v as any).key === 'string' && FIELD_TYPES.has((v as any).type);\n}","tryCatchPattern":"try { visualizationMetadata(value); } catch (e) { if (e instanceof Error && /fields\\[\\d+\\] is invalid/.test(e.message)) { /* show allowed types to author */ } throw e; }","preventionTips":["Keep a literal union type for field.type so the compiler catches typos.","Document the alias mapping (integer→number, date→temporal) next to your data-export code."],"tags":["cli","verify","visualization","validation"],"backgroundTag":null,"analyzedSha":"10f24d7ade75139093a9373b364f6bc91f3cd7db","analyzedAt":"2026-08-12T11:43:19.543Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}