Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inProcessExecution that propagates the conjure exceptions #1516

Merged
merged 10 commits into from
Mar 11, 2024

Conversation

crogoz
Copy link
Contributor

@crogoz crogoz commented Feb 29, 2024

Before this PR

Conjure exceptions were not propagated to gradle-conjure. We were only getting the exitCode.

before the exception looked like:

* What went wrong:
Execution failed for task ':types-api:rawIr'.
> Failed to generate conjure IR. The command 'conjure' with args [compile, /Volumes/git/service/types-api/build/conjure, /Volumes/git/service/types-api/build/conjure-ir/rawIr.conjure.json, --extensions, {"recommended-product-dependencies":[]}, --requireSafety] failed with exit code -1. Output above.

After this PR

Introduces a new inProcessExecution method that will re-throw any exception

* What went wrong:
Execution failed for task ':types-api:rawIr'.
> com.palantir.conjure.exceptions.ConjureIllegalStateException: Unknown LocalReferenceType: TypeName{name=Name1}
  
  Failed to generate conjure IR. The command '[compile, /Volumes/git/service/types-api/build/conjure, /Volumes/git/service/types-api/build/conjure-ir/rawIr.conjure.json, --extensions, {"recommended-product-dependencies":[]}, --requireSafety]' failed.

==COMMIT_MSG==
Add inProcessExecution that propagates the conjure exceptions
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Feb 29, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Add inProcessExecution that propagates the conjure exceptions

Check the box to generate changelog(s)

  • Generate changelog entry

@crogoz crogoz requested a review from CRogers February 29, 2024 16:08
if (ex == null) {
thrownException = Optional.ofNullable(ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems suspect - ex is null here, so we probably don't need this line.

? handleJsonMappingException((JsonMappingException) exception)
: exception.getMessage())
.collect(Collectors.joining("\n"));
commandLine.getErr().println(message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to this when called in process? Does it still print out to stderr?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is a setErr we can use on CommandLine to change it.

Copy link
Contributor Author

@crogoz crogoz Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-03-04 at 2 54 22 PM Yes, it does still log to stderr. the getErr() is the default [standardError](https://github.com/remkop/picocli/blob/main/src/main/java/picocli/CommandLine.java#L1311C16-L1311C19).

@VisibleForTesting
static CommandLine prepareCommand() {
return new CommandLine(new ConjureCli()).setExecutionExceptionHandler(new ExceptionHandler());
}

public static final class ExceptionHandler implements IExecutionExceptionHandler {

private Optional<Exception> thrownException = Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think we can write this a little more concisely/safely for future changes. We can keep the existing IExecutionExceptionHandler as is then write a wrapper IExecutionExceptionHandler that wraps the original one but catches the exception and saves it. Also sets the err and if that is written to, we make an exception from that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps with a TeeOutputStream to the original err if we want to preserve the current behaviour (maybe we don't need to though?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

CRogers
CRogers previously approved these changes Mar 4, 2024
@policy-bot policy-bot bot dismissed CRogers’s stale review March 4, 2024 16:16

Invalidated by push of e840abf

@crogoz crogoz requested a review from CRogers March 4, 2024 16:17
@bulldozer-bot bulldozer-bot bot merged commit a55ea92 into master Mar 11, 2024
5 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/capture-stderr branch March 11, 2024 15:06
@svc-autorelease
Copy link
Collaborator

Released 4.40.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants