@@ -5,9 +5,7 @@ use crate::{
55 ONE_OFF_QUEUE_DEPTH , UNAVAILABLE_WS ,
66 } ,
77 request_database:: { Handle , How } ,
8- ClippySnafu , CompileSnafu , Config , CratesSnafu , Error , EvaluateSnafu , ExecuteSnafu ,
9- FormatSnafu , GhToken , GistCreationSnafu , GistLoadingSnafu , MacroExpansionSnafu , MetricsToken ,
10- MiriSnafu , MiriVersionSnafu , Result , ShutdownCoordinatorSnafu , TimeoutSnafu , VersionsSnafu ,
8+ Config , GhToken , MetricsToken ,
119} ;
1210use async_trait:: async_trait;
1311use axum:: {
@@ -48,7 +46,7 @@ use tower_http::{
4846} ;
4947use tracing:: { error, error_span, field} ;
5048
51- use crate :: public_http_api as api;
49+ use crate :: { env :: PLAYGROUND_GITHUB_TOKEN , public_http_api as api} ;
5250
5351const ONE_HOUR : Duration = Duration :: from_secs ( 60 * 60 ) ;
5452const CORS_CACHE_TIME_TO_LIVE : Duration = ONE_HOUR ;
@@ -608,11 +606,19 @@ where
608606 Ok ( ( etag, cache_control, response) )
609607}
610608
609+ fn must_get ( token : & GhToken ) -> Result < String > {
610+ token
611+ . 0
612+ . as_ref ( )
613+ . map ( |s| String :: clone ( s) )
614+ . context ( NoGithubTokenSnafu )
615+ }
616+
611617async fn meta_gist_create (
612618 Extension ( token) : Extension < GhToken > ,
613619 Json ( req) : Json < api:: MetaGistCreateRequest > ,
614620) -> Result < Json < api:: MetaGistResponse > > {
615- let token = token . must_get ( ) ?;
621+ let token = must_get ( & token ) ?;
616622 gist:: create_future ( token, req. code )
617623 . await
618624 . map ( Into :: into)
@@ -624,7 +630,7 @@ async fn meta_gist_get(
624630 Extension ( token) : Extension < GhToken > ,
625631 Path ( id) : Path < String > ,
626632) -> Result < Json < api:: MetaGistResponse > > {
627- let token = token . must_get ( ) ?;
633+ let token = must_get ( & token ) ?;
628634 gist:: load_future ( token, & id)
629635 . await
630636 . map ( Into :: into)
@@ -980,6 +986,135 @@ where
980986 }
981987}
982988
989+ #[ derive( Debug , Snafu ) ]
990+ enum Error {
991+ #[ snafu( display( "Gist creation failed" ) ) ]
992+ GistCreation { source : octocrab:: Error } ,
993+
994+ #[ snafu( display( "Gist loading failed" ) ) ]
995+ GistLoading { source : octocrab:: Error } ,
996+
997+ #[ snafu( display( "{PLAYGROUND_GITHUB_TOKEN} not set up for reading/writing gists" ) ) ]
998+ NoGithubToken ,
999+
1000+ #[ snafu( display( "Unable to deserialize request" ) ) ]
1001+ Deserialization { source : serde_json:: Error } ,
1002+
1003+ #[ snafu( transparent) ]
1004+ EvaluateRequest {
1005+ source : api_orchestrator_integration_impls:: ParseEvaluateRequestError ,
1006+ } ,
1007+
1008+ #[ snafu( transparent) ]
1009+ CompileRequest {
1010+ source : api_orchestrator_integration_impls:: ParseCompileRequestError ,
1011+ } ,
1012+
1013+ #[ snafu( transparent) ]
1014+ ExecuteRequest {
1015+ source : api_orchestrator_integration_impls:: ParseExecuteRequestError ,
1016+ } ,
1017+
1018+ #[ snafu( transparent) ]
1019+ FormatRequest {
1020+ source : api_orchestrator_integration_impls:: ParseFormatRequestError ,
1021+ } ,
1022+
1023+ #[ snafu( transparent) ]
1024+ ClippyRequest {
1025+ source : api_orchestrator_integration_impls:: ParseClippyRequestError ,
1026+ } ,
1027+
1028+ #[ snafu( transparent) ]
1029+ MiriRequest {
1030+ source : api_orchestrator_integration_impls:: ParseMiriRequestError ,
1031+ } ,
1032+
1033+ #[ snafu( transparent) ]
1034+ MacroExpansionRequest {
1035+ source : api_orchestrator_integration_impls:: ParseMacroExpansionRequestError ,
1036+ } ,
1037+
1038+ #[ snafu( display( "The WebSocket worker panicked: {}" , text) ) ]
1039+ WebSocketTaskPanic { text : String } ,
1040+
1041+ #[ snafu( display( "Unable to find the available crates" ) ) ]
1042+ Crates {
1043+ source : orchestrator:: coordinator:: CratesError ,
1044+ } ,
1045+
1046+ #[ snafu( display( "Unable to find the available versions" ) ) ]
1047+ Versions {
1048+ source : orchestrator:: coordinator:: VersionsError ,
1049+ } ,
1050+
1051+ #[ snafu( display( "The Miri version was missing" ) ) ]
1052+ MiriVersion ,
1053+
1054+ #[ snafu( display( "Unable to shutdown the coordinator" ) ) ]
1055+ ShutdownCoordinator {
1056+ source : orchestrator:: coordinator:: Error ,
1057+ } ,
1058+
1059+ #[ snafu( display( "Unable to process the evaluate request" ) ) ]
1060+ Evaluate {
1061+ source : orchestrator:: coordinator:: ExecuteError ,
1062+ } ,
1063+
1064+ #[ snafu( display( "Unable to process the compile request" ) ) ]
1065+ Compile {
1066+ source : orchestrator:: coordinator:: CompileError ,
1067+ } ,
1068+
1069+ #[ snafu( display( "Unable to process the execute request" ) ) ]
1070+ Execute {
1071+ source : orchestrator:: coordinator:: ExecuteError ,
1072+ } ,
1073+
1074+ #[ snafu( display( "Unable to process the format request" ) ) ]
1075+ Format {
1076+ source : orchestrator:: coordinator:: FormatError ,
1077+ } ,
1078+
1079+ #[ snafu( display( "Unable to process the Clippy request" ) ) ]
1080+ Clippy {
1081+ source : orchestrator:: coordinator:: ClippyError ,
1082+ } ,
1083+
1084+ #[ snafu( display( "Unable to process the Miri request" ) ) ]
1085+ Miri {
1086+ source : orchestrator:: coordinator:: MiriError ,
1087+ } ,
1088+
1089+ #[ snafu( display( "Unable to process the macro expansion request" ) ) ]
1090+ MacroExpansion {
1091+ source : orchestrator:: coordinator:: MacroExpansionError ,
1092+ } ,
1093+
1094+ #[ snafu( display( "The operation timed out" ) ) ]
1095+ Timeout { source : tokio:: time:: error:: Elapsed } ,
1096+
1097+ #[ snafu( display( "Unable to spawn a coordinator task" ) ) ]
1098+ StreamingCoordinatorSpawn {
1099+ source : WebsocketCoordinatorManagerError ,
1100+ } ,
1101+
1102+ #[ snafu( display( "Unable to idle the coordinator" ) ) ]
1103+ StreamingCoordinatorIdle {
1104+ source : WebsocketCoordinatorManagerError ,
1105+ } ,
1106+
1107+ #[ snafu( display( "Unable to perform a streaming execute" ) ) ]
1108+ StreamingExecute { source : WebsocketExecuteError } ,
1109+
1110+ #[ snafu( display( "Unable to pass stdin to the active execution" ) ) ]
1111+ StreamingCoordinatorExecuteStdin {
1112+ source : tokio:: sync:: mpsc:: error:: SendError < ( ) > ,
1113+ } ,
1114+ }
1115+
1116+ type Result < T , E = Error > = :: std:: result:: Result < T , E > ;
1117+
9831118pub ( crate ) mod api_orchestrator_integration_impls {
9841119 use orchestrator:: coordinator:: * ;
9851120 use snafu:: prelude:: * ;
0 commit comments