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

Throwable toString override #1263

Merged
merged 6 commits into from
Nov 2, 2023
Merged

Conversation

daddykotex
Copy link
Contributor

@daddykotex daddykotex commented Oct 16, 2023

Default toString on Throwable prints the classname. This is suboptimal when we could have the case class toString implementation available.

PR Checklist (not all items are relevant to all PRs)

  • Added unit-tests (for runtime code)
  • Update bootstrapped code + smoke tests (when the rendering logic is modified)
  • Added build-plugins integration tests (when reflection loading is required at codegen-time)
  • Added alloy compliance tests (when simpleRestJson protocol behaviour is expanded/updated)
  • Updated dynamic module to match generated-code behaviour
  • Added documentation
  • Updated changelog

@daddykotex daddykotex changed the title Dfrancoeur/0.18 throwable tostring Throwable tostring override Oct 16, 2023
@daddykotex daddykotex changed the title Throwable tostring override Throwable toString override Oct 16, 2023
@daddykotex daddykotex mentioned this pull request Oct 16, 2023
7 tasks
@daddykotex daddykotex force-pushed the dfrancoeur/0.18-throwable-tostring branch from c5a55ef to fd94ab7 Compare October 17, 2023 13:50
@@ -801,6 +802,10 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self =>
)
}

// Default toString on Throwable prints the classname, instead we use the case class toString.
private def defaultThrowableGetMessage =
line"override def toString(): $string_ = $scalaRuntime._toString(this)"
Copy link
Contributor

@Baccata Baccata Oct 31, 2023

Choose a reason for hiding this comment

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

Sorry for reviewing this only now. Anyway, the documentation of the ScalaRunTime object states the following :

/** The object ScalaRunTime provides support methods required by
 *  the scala runtime.  All these methods should be considered
 *  outside the API and subject to change or removal without notice.
 */

therefore, I'm not comfortable with this implementation. Can you elaborate on the rationale for wanting to use this ? I guess it's just for the convenience of it.

In any case, we can render an actual implementation that'd be using a StringBuilder quite easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that completely, that's fair.

In any case, we can render an actual implementation that'd be using a StringBuilder quite easily.

Any format we prefer? For Foo(bar: String), default implementation renders Foo(barValue), we can choose how to render if we implement it ourselves

I chose to implement toString, because implementing getMessage would
lead to `smithy4s.example.ClientError: smithy4s.example.ClientError(400, "oops")`
which felt weird
@daddykotex daddykotex force-pushed the dfrancoeur/0.18-throwable-tostring branch from e886e5d to 2f51c44 Compare October 31, 2023 15:46
@Baccata Baccata merged commit c3190c4 into series/0.18 Nov 2, 2023
11 checks passed
@Baccata Baccata deleted the dfrancoeur/0.18-throwable-tostring branch November 2, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants