{"record":{"id":"c7ec26452dd301ef","repo":"mifi/lossless-cut","slug":"no-valid-segments-found","errorCode":null,"errorMessage":"No valid segments found","messagePattern":"No valid segments found","errorType":"exception","errorClass":"UserFacingError","httpStatus":null,"severity":"error","filePath":"src/renderer/src/hooks/useSegments.tsx","lineNumber":170,"sourceCode":"\n  const clearSegments = useCallback(() => {\n    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,","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/mifi/lossless-cut/blob/3b9a59c288bf6e11076b583c932cfa48ddab3b02/src/renderer/src/hooks/useSegments.tsx#L152-L188","documentation":"Thrown by loadCutSegments() when the segments array passed in has length 0. The function exists to load/import a set of cut segments into the timeline, and an empty input would wipe the current segment list without adding anything. It is an explicit precondition before the maxSegmentsAllowed check and before any state mutation.","triggerScenarios":"Calling loadCutSegments({ segments: [], ... }) from an EDL/CSV import that produced zero segments; a parser returned an empty array (e.g. an EDL with no rows that passed earlier guards); a programmatic caller passing an uninitialised array.","commonSituations":"An imported file parsed to no usable segments (empty cut list); a copy/move operation that filtered out all segments; a bug where a parser returns [] unexpectedly; selecting nothing and triggering a load.","solutions":["Check segments.length > 0 before calling loadCutSegments; skip the call if empty.","Investigate why the upstream parser produced zero segments (see related parse errors).","Show the user 'no segments to import' instead of attempting the load.","When appending, guard the empty case so an empty import does not replace existing segments."],"exampleFix":"// before\nloadCutSegments({ segments, append });\n\n// after\nif (segments.length === 0) {\n  toast.info('No segments to import');\n  return;\n}\nloadCutSegments({ segments, append });","handlingStrategy":"validation","validationCode":"// Guard the load call against an empty segment list\nif (!Array.isArray(segments) || segments.length === 0) {\n  toast.info('No segments to import');\n  return;\n}\nloadCutSegments({ segments, append });","typeGuard":"const hasSegments = (segs: unknown): segs is SegmentBase[] => Array.isArray(segs) && segs.length > 0;","tryCatchPattern":"try {\n  loadCutSegments({ segments, append });\n} catch (err) {\n  if (err instanceof UserFacingError && /No valid segments/.test(err.message)) {\n    showError('The imported file produced no segments.');\n    return;\n  }\n  throw err;\n}","preventionTips":["Check segments.length > 0 before calling loadCutSegments.","Investigate upstream parsers that unexpectedly return empty arrays.","When appending, ignore empty imports so existing segments are preserved.","Show the user a clear 'nothing to import' message for empty results."],"tags":["segments","import","validation","state"],"backgroundTag":null,"analyzedSha":"3b9a59c288bf6e11076b583c932cfa48ddab3b02","analyzedAt":"2026-08-12T20:54:25.651Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}