{"record":{"id":"4127397d1afb7b57","repo":"eythaann/Seelen-UI","slug":"the-inner-array-cannot-be-null-or-undefined","errorCode":null,"errorMessage":"The inner array cannot be null or undefined.","messagePattern":"The inner array cannot be null or undefined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libs/core/src/utils/List.ts","lineNumber":13,"sourceCode":"/**\n * A generic, abstract class for managing an array-like collection of items.\n * @template T The type of elements stored in the list.\n */\nexport abstract class List<T = unknown> {\n  /**\n   * Constructor for the List class.\n   * @param inner The internal array that stores the elements.\n   * @throws Error if the provided array is not\n   */\n  constructor(protected inner: T[]) {\n    if (!inner) {\n      throw new Error(\"The inner array cannot be null or undefined.\");\n    }\n    if (!Array.isArray(inner)) {\n      throw new Error(\"The inner array must be an array.\");\n    }\n  }\n\n  public [Symbol.iterator](): Iterable<T> {\n    return this.inner[Symbol.iterator]();\n  }\n\n  public get length(): number {\n    return this.inner.length;\n  }\n\n  /**\n   * Provides direct access to the internal array of items.\n   * @returns A reference to the internal array of items.\n   */","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/libs/core/src/utils/List.ts#L1-L31","documentation":"The List class wraps an internal array and validates it in its constructor. Passing null or undefined as the inner array makes every later operation on the List meaningless, so the constructor throws immediately with this message.","triggerScenarios":"new List(null) or new List(undefined) directly; more commonly new List(someMaybeUndefined) where the value came from an optional lookup (find(), map.get()), an unvalidated API/IPC response, a missing object property, or a parameter without a default.","commonSituations":"Reading a property that does not exist (data.items when items is absent); a backend command returning null for an empty collection; passing find()/get() results straight into List; JSON payloads missing expected fields.","solutions":["Coerce to an array at the call site before constructing: new List(value ?? []).","Validate the source data (schema or Array.isArray check) before wrapping it in List.","Fix the upstream producer so empty results are [] instead of null/undefined.","Give parameters that feed List a default: function make(items: T[] = [])."],"exampleFix":"// before: const list = new List(items); // items may be undefined\n// after: const list = new List(items ?? []);","handlingStrategy":"validation","validationCode":"if (value == null) throw new Error('cannot build List from null/undefined'); const list = new List(value ?? []);","typeGuard":"function isArrayish<T>(v: T[] | null | undefined): v is T[] { return v != null; }","tryCatchPattern":"let list: List<T>; try { list = new List(maybeItems); } catch (e) { if (e instanceof Error && e.message.includes('cannot be null or undefined')) { list = new List([]); } else { throw e; } }","preventionTips":["Default optional array parameters to [].","Validate API/IPC payloads with a schema before wrapping in List.","Never pass possibly-undefined lookups (find(), map.get()) straight into List.","Prefer `x ?? []` at every List construction site."],"tags":["validation","constructor","null"],"backgroundTag":"null-or-undefined-argument","analyzedSha":"dee4aaa94066c5d0888ab25554864862fc47be15","analyzedAt":"2026-09-03T10:20:37.842Z","contentChangedAt":"2026-09-03T10:20:37.842Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}