zlucia commited on
Commit
88f467f
1 Parent(s): dd08c4f

Add exception handling

Browse files
Files changed (1) hide show
  1. pile-of-law.py +15 -12
pile-of-law.py CHANGED
@@ -255,15 +255,18 @@ class PileOfLaw(datasets.GeneratorBasedBuilder):
255
  id_ = 0
256
  for filepath in filepaths:
257
  logger.info("generating examples from = %s", filepath)
258
- with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
259
- for line in f:
260
- if line:
261
- example = json.loads(line)
262
- if example is not None and isinstance(example, dict):
263
- yield id_, {
264
- "text": example.get("text", ""),
265
- "created_timestamp": example.get("created_timestamp", ""),
266
- "downloaded_timestamp": example.get("downloaded_timestamp", ""),
267
- "url": example.get("url", "")
268
- }
269
- id_ += 1
 
 
 
 
255
  id_ = 0
256
  for filepath in filepaths:
257
  logger.info("generating examples from = %s", filepath)
258
+ try:
259
+ with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
260
+ for line in f:
261
+ if line:
262
+ example = json.loads(line)
263
+ if example is not None and isinstance(example, dict):
264
+ yield id_, {
265
+ "text": example.get("text", ""),
266
+ "created_timestamp": example.get("created_timestamp", ""),
267
+ "downloaded_timestamp": example.get("downloaded_timestamp", ""),
268
+ "url": example.get("url", "")
269
+ }
270
+ id_ += 1
271
+ except:
272
+ print("Error reading file:", filepath)