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 generic compilation error message in runner #79

Merged
merged 2 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/scala/playground/CommandProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ object CommandProvider {
}
}
}
.recoverWith { case _: CompilationFailed =>
CommandResultReporter[F].onCompilationFailed
}

}
.merge
}
Expand Down
29 changes: 17 additions & 12 deletions core/src/main/scala/playground/CommandResultReporter.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package playground

import cats.FlatMap
import cats.Id
import cats.Monad
import cats.data.NonEmptyList
import cats.effect.kernel.Ref
import cats.implicits._
Expand All @@ -12,14 +12,24 @@ import playground.smithyql.WithSource

import Runner.Issue.ProtocolIssues

trait CommandResultReporter[F[_]] {
type RequestId
def onUnsupportedProtocol(issues: ProtocolIssues): F[Unit]
def onIssues(issues: NonEmptyList[Throwable]): F[Unit]
def onCompilationFailed: F[Unit]
def onQueryCompiled(parsed: Query[Id], compiled: CompiledInput): F[RequestId]
def onQuerySuccess(parsed: Query[Id], requestId: RequestId, output: InputNode[Id]): F[Unit]
def onQueryFailure(e: Throwable, compiled: CompiledInput, requestId: RequestId): F[Unit]
}

object CommandResultReporter {
def apply[F[_]](implicit F: CommandResultReporter[F]): F.type = F

def instance[
F[_]: Feedback: FlatMap: Ref.Make
F[_]: Feedback: Monad: Ref.Make
]: F[CommandResultReporter[F]] = Ref[F].of(0).map(withRequestCounter(_))

def withRequestCounter[F[_]: Feedback: FlatMap](
def withRequestCounter[F[_]: Feedback: Monad](
requestCounter: Ref[F, Int]
): CommandResultReporter[F] =
new CommandResultReporter[F] {
Expand All @@ -43,6 +53,10 @@ object CommandResultReporter {
issues.map(_.toString).mkString_("\n\n")
)

def onCompilationFailed: F[Unit] = Feedback[F].showErrorMessage(
"Couldn't run query because of compilation errors."
)

def onQueryCompiled(parsed: Query[Id], compiled: CompiledInput): F[RequestId] =
Feedback[F].showOutputPanel *>
requestCounter.updateAndGet(_ + 1).flatTap { requestId =>
Expand Down Expand Up @@ -77,12 +91,3 @@ object CommandResultReporter {
}

}

trait CommandResultReporter[F[_]] {
type RequestId
def onUnsupportedProtocol(issues: ProtocolIssues): F[Unit]
def onIssues(issues: NonEmptyList[Throwable]): F[Unit]
def onQueryCompiled(parsed: Query[Id], compiled: CompiledInput): F[RequestId]
def onQuerySuccess(parsed: Query[Id], requestId: RequestId, output: InputNode[Id]): F[Unit]
def onQueryFailure(e: Throwable, compiled: CompiledInput, requestId: RequestId): F[Unit]
}