{"record":{"id":"6d55b2dd990e7094","repo":"angular/components","slug":"formats-array-must-not-be-empty-6d55b2","errorCode":null,"errorMessage":"Formats array must not be empty.","messagePattern":"Formats array must not be empty\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material-luxon-adapter/adapter/luxon-date-adapter.ts","lineNumber":185,"sourceCode":"    const options = this._getOptions();\n\n    return this._useUTC ? LuxonDateTime.utc(options) : LuxonDateTime.local(options);\n  }\n\n  parse(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {\n    const options: LuxonDateTimeOptions = this._getOptions();\n\n    if (typeof value == 'string' && value.length > 0) {\n      const iso8601Date = LuxonDateTime.fromISO(value, options);\n\n      if (this.isValid(iso8601Date)) {\n        return iso8601Date;\n      }\n\n      const formats = Array.isArray(parseFormat) ? parseFormat : [parseFormat];\n\n      if (!parseFormat.length) {\n        throw Error('Formats array must not be empty.');\n      }\n\n      for (const format of formats) {\n        const fromFormat = LuxonDateTime.fromFormat(value, format, options);\n\n        if (this.isValid(fromFormat)) {\n          return fromFormat;\n        }\n      }\n\n      return this.invalid();\n    } else if (typeof value === 'number') {\n      return LuxonDateTime.fromMillis(value, options);\n    } else if (value instanceof Date) {\n      return LuxonDateTime.fromJSDate(value, options);\n    } else if (value instanceof LuxonDateTime) {\n      return LuxonDateTime.fromMillis(value.toMillis(), options);\n    }","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material-luxon-adapter/adapter/luxon-date-adapter.ts#L167-L203","documentation":"The Luxon adapter's parse method needs at least one format to try against the input string. It normalizes parseFormat to an array but then checks `!parseFormat.length` on the raw input, throwing when an empty array is supplied. Like the date-fns adapter, it fails fast rather than silently returning null.","triggerScenarios":"Calling `adapter.parse(value, [])` (empty formats array) or via parseTime/result helpers with an empty format list configured in MAT_DATE_FORMATS parse.dateInput.","commonSituations":"Empty parse formats from locale-driven config that failed to load; passing `[]` instead of omitting the argument (ISO-8601 fallback path only triggers for falsy/undefined parseFormat); dynamic format lists filtered to empty.","solutions":["Pass a non-empty format array or string: `adapter.parse(value, ['yyyy-MM-dd'])`.","To rely on ISO-8601 fallback, pass undefined/null rather than an empty array.","Audit MAT_DATE_FORMATS parse settings for empty arrays.","Guard dynamic lists: `const fmts = formats.length ? formats : undefined;` before parsing."],"exampleFix":"// before\nadapter.parse('2024-01-15', []); // throws\n\n// after\nadapter.parse('2024-01-15', ['yyyy-MM-dd']);\n// or use ISO fallback:\nadapter.parse('2024-01-15', formats.length ? formats : undefined);","handlingStrategy":"validation","validationCode":"const formats: string | string[] = getConfiguredFormats();\nif (Array.isArray(formats) && formats.length === 0) {\n  // fall back to ISO-8601 handling by passing undefined\n  return adapter.parse(value, undefined);\n}\nreturn adapter.parse(value, formats);","typeGuard":"function isNonEmptyFormatList(f: string | string[]): boolean {\n  return typeof f === 'string' ? f.length > 0 : f.length > 0;\n}","tryCatchPattern":"try {\n  return adapter.parse(value, formats);\n} catch (e) {\n  if (String(e.message).includes('Formats array must not be empty')) {\n    return adapter.parse(value, undefined); // ISO fallback\n  }\n  throw e;\n}","preventionTips":["Pass undefined (not []) to get ISO-8601 fallback parsing.","Audit MAT_DATE_FORMATS parse.dateInput for empty arrays after locale config changes.","Guard dynamically generated format lists with a default entry.","Add a startup assertion that configured parse formats are non-empty."],"tags":["angular-material","luxon","date-parsing","invalid-argument","developer-error"],"backgroundTag":"empty-formats-array","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}