{"record":{"id":"9a3b695f1bd8a658","repo":"mifi/lossless-cut","slug":"tried-to-create-too-many-segments-max-maxsegmen","errorCode":null,"errorMessage":"Tried to create too many segments (max {{maxSegmentsAllowed}}.)","messagePattern":"Tried to create too many segments \\(max (.+?)\\}\\.\\)","errorType":"exception","errorClass":"UserFacingError","httpStatus":null,"severity":"error","filePath":"src/renderer/src/hooks/useSegments.tsx","lineNumber":172,"sourceCode":"    clearSegColorCounter();\n    safeSetCutSegments([]);\n  }, [clearSegColorCounter, safeSetCutSegments]);\n\n  const shuffleSegments = useCallback(() => safeSetCutSegments((existingSegments) => [\n    ...existingSegments.filter((s) => !s.selected),\n    ...shuffleArray(existingSegments.filter((s) => s.selected)),\n  ]), [safeSetCutSegments]);\n\n  // todo combine with safeSetCutSegments?\n  const loadCutSegments = useCallback(({ segments, append, clampDuration, getNextCurrentSegIndex }: {\n    segments: SegmentBase[],\n    append: boolean,\n    clampDuration?: number | undefined,\n    getNextCurrentSegIndex?: (newEdl: SegmentBase[]) => number,\n  }) => {\n    if (segments.length === 0) throw new UserFacingError(i18n.t('No valid segments found'));\n\n    if (segments.length > maxSegmentsAllowed) throw new UserFacingError(i18n.t('Tried to create too many segments (max {{maxSegmentsAllowed}}.)', { maxSegmentsAllowed }));\n\n    if (!append) clearSegColorCounter();\n\n    safeSetCutSegments((existingSegments) => {\n      const needToAppend = append && !isInitialSegment(existingSegments);\n      let newSegments = segments.map((segment, i) => createIndexedSegment({ segment, incrementCount: needToAppend || i > 0 }));\n      if (needToAppend) newSegments = [...existingSegments, ...newSegments];\n      if (getNextCurrentSegIndex) setCurrentSegIndex(getNextCurrentSegIndex(newSegments));\n      return newSegments;\n    }, clampDuration);\n  }, [clearSegColorCounter, createIndexedSegment, safeSetCutSegments]);\n\n  const detectSegments = useCallback(async ({ name, workingText, errorText, fn }: {\n    name: string,\n    workingText: string,\n    errorText: string,\n    fn: (onSegmentDetected: (seg: SegmentBase) => void) => Promise<{ ffmpegArgs: string[] }>,\n  }) => {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/mifi/lossless-cut/blob/3b9a59c288bf6e11076b583c932cfa48ddab3b02/src/renderer/src/hooks/useSegments.tsx#L154-L190","documentation":"Thrown by loadCutSegments() when segments.length exceeds maxSegmentsAllowed (imported from util/constants). It protects the UI and memory from an pathologically large segment list that would make the timeline and segment list unusable. The error message is i18n-interpolated with the actual limit so the user knows the threshold.","triggerScenarios":"Importing an EDL/CSV that contains more than maxSegmentsAllowed rows; a programmatic generator producing an unbounded number of segments; a malformed file whose structure caused row explosion (e.g. one row per frame).","commonSituations":"A huge CSV (thousands of rows) from a detection tool (scene detection, ad detection); an EDL with per-frame cuts; a generator script run with too many entries; merging many EDLs together.","solutions":["Reduce the number of segments in the source file to at or below maxSegmentsAllowed before importing.","Split the import into multiple smaller EDLs.","If the limit is genuinely too low for the use case, raise maxSegmentsAllowed in util/constants (mind memory/perf).","Pre-count rows and warn the user before attempting the import."],"exampleFix":"// before\nloadCutSegments({ segments, append });\n\n// after\nif (segments.length > maxSegmentsAllowed) {\n  toast.error(`Too many segments (${segments.length}). Limit is ${maxSegmentsAllowed}.`);\n  return;\n}\nloadCutSegments({ segments, append });","handlingStrategy":"validation","validationCode":"import { maxSegmentsAllowed } from './util/constants';\nif (segments.length > maxSegmentsAllowed) {\n  throw new Error(`Refusing to import ${segments.length} segments (limit ${maxSegmentsAllowed}). Split the file or raise the limit.`);\n}","typeGuard":"const withinSegmentLimit = (segs: unknown): segs is SegmentBase[] =>\n  Array.isArray(segs) && segs.length <= maxSegmentsAllowed;","tryCatchPattern":"try {\n  loadCutSegments({ segments, append });\n} catch (err) {\n  if (err instanceof UserFacingError && /too many segments/.test(err.message)) {\n    showError(`Too many segments (${segments.length}). Limit is ${maxSegmentsAllowed}.`);\n    return;\n  }\n  throw err;\n}","preventionTips":["Pre-count rows in the source EDL/CSV and warn before importing if it exceeds the limit.","Split large cut lists into multiple smaller EDLs.","Raise maxSegmentsAllowed only after considering memory/performance impact.","Filter out unwanted segments (e.g. below a duration threshold) before import."],"tags":["segments","import","limits","validation","performance"],"backgroundTag":null,"analyzedSha":"3b9a59c288bf6e11076b583c932cfa48ddab3b02","analyzedAt":"2026-08-12T20:54:25.651Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}