Next question: I'm generating the code from a pro...
# plugins
f
Next question: I'm generating the code from a process. That might fail (for whatever reason, be it transient hardware issue or user typed error in the source). What's the correct way to pass that failure along the call stack? Currently I have this, but the build just continues on merrily other than the console output.
Copy code
output_snapshot = []
    if result.exit_code == 0:
        <http://logger.info|logger.info>(f"✓ Generated {output_file_name} from {source_file_name}")
        output_snapshot = await Get(Snapshot, Digest, result.output_digest)
    else:
        logger.error(f"✗ Failed to generate {output_file_name}: {result.stderr}")
        output_snapshot = await Get(Snapshot, Digest, EMPTY_DIGEST)
    
    return GeneratedSources(output_snapshot)
f
If the build should fail, just raise an exception. The rules engine will propagate it correctly.
f
Any particular type? Or just make my own?
f
No type in particular. Your own or
ValueError
is fine.
(Existing Pants code uses both approaches with no real consistency.)
f
ok, easy enough. Thanks!
g
There is also a
FallibleProcessResult
which can be useful in some situations; f.ex. if you want to do analysis and pass more info up the stack. The regular
Get(ProcessResult, Process)
uses that as an intermediary: https://github.com/pantsbuild/pants/blob/f1252a157ed28cba64ed5d670c55925b04256a53/src/python/pants/engine/process.py#L375-L397
f
Yes, I'm already using that to print out stderr in the case of failure. I'm also planning to raise an exception that has the exit status.