diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-09-19 16:40:17 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-09-19 17:50:20 +0530 |
commit | 33ccae2827fee3cc9734f4f0dfbeecae98c198aa (patch) | |
tree | 38d0f25794c9f3788d54036be991a5702c2dd4e5 /bin/nixpkgs_dag.py | |
parent | 14bbfeb7d6ce076fcc65d604a2f7293503d679be (diff) |
bin/nixpkgs_dag: better error handling
Diffstat (limited to 'bin/nixpkgs_dag.py')
-rwxr-xr-x | bin/nixpkgs_dag.py | 15 |
1 files 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() |