comparison bin/ix.py @ 129:b51d65ed6c89

improve error handling
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Fri, 09 Jul 2021 13:45:43 +0000
parents 5b0ec642ee9b
children bb0153be65b5
comparison
equal deleted inserted replaced
128:ababa631a10f 129:b51d65ed6c89
66 file.seek(offset) 66 file.seek(offset)
67 bv=memoryview(buf)[:length] 67 bv=memoryview(buf)[:length]
68 nb=file.readinto(bv) 68 nb=file.readinto(bv)
69 file.close() 69 file.close()
70 if nb!=length: 70 if nb!=length:
71 print("losing",file.name,length,nb,file=sys.stderr) 71 raise ValueError("Chunk read losing: %s, got %s expected %s at %s"%(file.name,
72 nb,length,offset))
72 if whole and options.zipped: 73 if whole and options.zipped:
73 _output(bv) 74 _output(bv)
74 return 75 return
75 gzip_chunk = io.BytesIO(bv) 76 gzip_chunk = io.BytesIO(bv)
76 uv=memoryview(buf)[length:] 77 uv=memoryview(buf)[length:]
204 for l in sys.stdin: 205 for l in sys.stdin:
205 m=CDX.search(l) 206 m=CDX.search(l)
206 if m is None: 207 if m is None:
207 if l.find('/robotstxt/')>-1: 208 if l.find('/robotstxt/')>-1:
208 continue 209 continue
209 print("index line problem: \"%s\""%l.lstrip(),file=sys.stderr) 210 print("index line problem: \"%s\""%l,file=sys.stderr,end='')
210 exit(2) 211 exit(2)
211 f=FPAT%(m[3:7]) 212 f=FPAT%(m[3:7])
212 process(pa,buf,f, 213 try:
213 int(m[2]),int(m[1]),whole) 214 process(pa,buf,f,
215 int(m[2]),int(m[1]),whole)
216 except Exception as e:
217 print("Process fail: %s, input line:\n %s"%(e,l),
218 file=sys.stderr,end='')
219 exit(3)
214 elif pa.length is not None: 220 elif pa.length is not None:
215 print(pa.filename,file=sys.stderr) 221 print(pa.filename,file=sys.stderr)
216 process(pa,buf,FPAT%tuple(pa.filename.split('/')), 222 process(pa,buf,FPAT%tuple(pa.filename.split('/')),
217 pa.offset,pa.length,whole) 223 pa.offset,pa.length,whole)
218 else: 224 else: