Hi, in your opinion what would be the best way to ...
# python
a
Hi, in your opinion what would be the best way to end a Pulumi run earlier due to an foreseeable error? I've been raising exceptions, which triggers an exit, but they're not as eye-catching as doing a log.error().
d
You could do a
sys.exit(1)
after the log.error. To make it cleaner, wrap it in a function:
Copy code
def fatal(msg: str, resource: pulumi.Resource = None):
  log.error(msg, resource=resource)
  sys.exit(1)
You could also pass in the exception to the function and throw it after the log:
Copy code
msg = str(exc)
log.error(msg)
throw exc
Though I'm not sure how that will look visually
a
The problem with sys.exit() is that it's not clean
And answering your last question, it would look something like:
Copy code
error: This is my custom error, it's all gone downhill
error: Program failed with an unhandled exception:
...
I think I'll stay with what I have
Thanks
d
I'm unsure what you mean by "not clean"
a
It means I've confused it with
os._exit()
😅
d
Haha, OK
I read through the launcher script, it looks like you'll get a cleaner error by using
pulumi.RunError
as the base of your exceptions: https://www.pulumi.com/docs/reference/pkg/python/pulumi/#pulumi.RunError
a
Oh, nice, thanks
With
pulumi.RunError
you essentially get what I want, which is a pretty error message followed by a clean exit, without a stack trace. 👍