{"record":{"id":"6cf39b500f543ac1","repo":"karatelabs/karate","slug":"failed-to-read-next-line","errorCode":null,"errorMessage":"failed to read next line","messagePattern":"failed to read next line","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java","lineNumber":260,"sourceCode":"        public boolean hasNext() {\n            if (hasNextCalled) {\n                return nextLine != null;\n            }\n            hasNextCalled = true;\n            if (currentIndex >= size) {\n                closeReader();\n                return false;\n            }\n            try {\n                nextLine = reader.readLine();\n                if (nextLine == null) {\n                    closeReader();\n                    return false;\n                }\n                return true;\n            } catch (IOException e) {\n                closeReader();\n                throw new RuntimeException(\"failed to read next line\", e);\n            }\n        }\n\n        @Override\n        public Object next() {\n            if (!hasNextCalled) {\n                hasNext();\n            }\n            if (nextLine == null) {\n                throw new NoSuchElementException();\n            }\n            hasNextCalled = false;\n            currentIndex++;\n            return deserializeItem(nextLine);\n        }\n\n        private void closeReader() {\n            try {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java#L242-L278","documentation":"DiskBackedIterator.hasNext() wraps IOException from reading the next line of the backing file in a RuntimeException with this message, after closing the reader. It signals the sequential read over the temp file failed mid-iteration.","triggerScenarios":"Disk I/O error or file deleted/truncated while the iterator is mid-read; descriptor closed unexpectedly; filesystem became unavailable during iteration.","commonSituations":"Long iterations over big lists on unstable storage; tmp reapers deleting the file partway through; resource exhaustion on the host.","solutions":["Inspect the chained IOException cause","Iterate soon after creation and complete the iteration without long pauses","Keep the temp file on stable storage and protected from external cleanup","Catch RuntimeException around iteration if partial-failure recovery is needed"],"exampleFix":"// before\nwhile (it.hasNext()) { process(it.next()); } // no failure handling\n// after\ntry {\n    while (it.hasNext()) { process(it.next()); }\n} catch (RuntimeException e) {\n    log.error(\"iteration failed\", e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"if (backingFileOf(list) == null || !backingFileOf(list).exists()) throw new IOException(\"backing file missing before iteration\");","typeGuard":"boolean canReadBacking(DiskBackedList l) { try { var it = l.iterator(); it.hasNext(); return true; } catch (RuntimeException e) { return false; } }","tryCatchPattern":"try { while (it.hasNext()) process(it.next()); } catch (RuntimeException e) { if (\"failed to read next line\".equals(e.getMessage())) { log.error(\"disk read failed mid-iteration\", e.getCause()); } throw e; }","preventionTips":["Complete iterations without long pauses","Keep temp storage stable and monitored","Watch the IOException cause for hardware/descriptor issues"],"tags":["io","file-read","iterator","temp-file"],"backgroundTag":"file-read-failed","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}