Skip to content

Commit

Permalink
[python] Print nicer errors in gramine-manifest
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Kowalczyk <[email protected]>
  • Loading branch information
mkow committed Apr 29, 2024
1 parent 53f5511 commit 50432b0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions python/gramine-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import click
import voluptuous

try:
from tomllib import TOMLDecodeError
except ImportError:
from tomli import TOMLDecodeError

from graminelibos import Manifest

def validate_define(_ctx, _param, values):
Expand All @@ -28,9 +33,13 @@ def validate_define(_ctx, _param, values):
@click.pass_context
def main(ctx, string, define, infile, outfile, check):
if not bool(string) ^ bool(infile):
click.get_current_context().fail('specify exactly one of (infile, -c)')
ctx.fail('specify exactly one of (infile, -c)')
template = infile.read() if infile else string
manifest = Manifest.from_template(template, define)
try:
manifest = Manifest.from_template(template, define)
except TOMLDecodeError as err:
click.echo(f'ERROR: failed to parse manifest template: {err!s}', err=True)
ctx.exit(1)

if check:
try:
Expand Down

0 comments on commit 50432b0

Please sign in to comment.