From 33ccae2827fee3cc9734f4f0dfbeecae98c198aa Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Thu, 19 Sep 2024 16:40:17 +0530 Subject: bin/nixpkgs_dag: better error handling --- bin/nixpkgs_dag.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/nixpkgs_dag.py b/bin/nixpkgs_dag.py index 7b8adea..4f574f0 100755 --- a/bin/nixpkgs_dag.py +++ b/bin/nixpkgs_dag.py @@ -5,6 +5,7 @@ # The DAG is represented using an adjacency list and saved in a SQLite db import re +import sys import subprocess import json import sqlite3 @@ -19,13 +20,15 @@ class drv: self.cursor = cursor j = json.loads(drv_string) - if 'drvPath' not in j: - raise TypeError + if 'error' in j: + raise TypeError(f'{j['attrPath']}: Failed to evaluate') + elif 'drvPath' not in j: + raise TypeError(f'{j['attrPath']}: Failed to read drvPath') pname = self.pname_from_drv_path(j['drvPath']) print(pname) if pname is None: - raise TypeError + raise TypeError(f'{j['attrPath']}: Failed to read pname') self.pname = pname for input_drv in j['inputDrvs']: @@ -58,7 +61,7 @@ class drv: VALUES (?) """, (pname,)) if s.lastrowid is None: - raise TypeError + raise TypeError('Failed to get lastrowid') return s.lastrowid @@ -79,7 +82,7 @@ if __name__ == '__main__': proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) if proc.stdout is None: - raise TypeError + raise EOFError('Failed to evaluate nixpkgs') con = sqlite3.connect('nixpkgs_dag.db') cur = con.cursor() @@ -101,7 +104,7 @@ if __name__ == '__main__': d = drv(line.decode('utf-8'), cur) d.db_push() except Exception as e: - print(str(e)) + print(f'>>> {e}', file=sys.stderr) con.commit() con.close() -- cgit v1.2.3