void (@NotNull PsiFile file) { List<String> errors = new ArrayList<>(); file.accept(new PsiRecursiveElementVisitor() { @Override public void visitErrorElement(@NotNull PsiErrorElement element) { errors.add(element.getTextOffset() + ": " + element.getErrorDescription()); super.visitErrorElement(element); } }); if (!errors.isEmpty()) { fail("Found PsiElement errors at offsets:\n" + String.join("\n", errors)); } }