Skip to content

Commit

Permalink
Show errors in filing issues/PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Sep 11, 2024
1 parent ee6995f commit 2e763f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions js/packages/repo-quest/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
events,
type QuestConfig,
type QuestState,
type Result,
type Stage,
type StageState,
type StateDescriptor,
Expand Down Expand Up @@ -88,6 +89,17 @@ let ErrorView: React.FC<{ message: string; action: string }> = ({
return null;
};

async function tryAwait<T>(
promise: Promise<Result<T, string>>,
action: string,
setMessage: (message: ErrorMessage) => void
) {
let result = await promise;
if (result.status === "error") {
setMessage({ action, message: result.error });
}
}

let GithubLoader = () => (
<Await promise={commands.getGithubToken()}>
{token =>
Expand Down Expand Up @@ -343,6 +355,7 @@ let StageView: React.FC<{
state: QuestState;
}> = ({ index, stage, state }) => {
let loader = useContext(Loader.context)!;
let setMessage = useContext(ErrorContext)!;
return (
<li>
<div>
Expand All @@ -354,7 +367,13 @@ let StageView: React.FC<{
<button
type="button"
onClick={() =>
loader.loadAwait(commands.fileFeatureAndIssue(index))
loader.loadAwait(
tryAwait(
commands.fileFeatureAndIssue(index),
"Filing issue or feature PR",
setMessage
)
)
}
>
{stage.stage["no-starter"]
Expand Down Expand Up @@ -384,7 +403,13 @@ let StageView: React.FC<{
<button
type="button"
onClick={() =>
loader.loadAwait(commands.fileSolution(index))
loader.loadAwait(
tryAwait(
commands.fileSolution(index),
"Filing solution PR",
setMessage
)
)
}
>
File reference solution
Expand Down
2 changes: 1 addition & 1 deletion rs/crates/repo-quest/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::json;
use specta::Type;
use std::{env, fs, process::Command, sync::Arc, time::Duration};
use std::{fs, process::Command, sync::Arc, time::Duration};
use tokio::{time::timeout, try_join};
use tracing::warn;

Expand Down

0 comments on commit 2e763f5

Please sign in to comment.