@@ -18,7 +18,7 @@ import {
1818 type PullRequestProviderApi ,
1919} from "@t3tools/source-control-core/server/PullRequestProvider" ;
2020
21- import { isTangledCliError , TangledAuthStatusSchema , TangledCli } from "./TangledCli.ts" ;
21+ import { TangledAuthStatusSchema , TangledCli , type TangledCliError } from "./TangledCli.ts" ;
2222import {
2323 numberPulls ,
2424 offsetFromRows ,
@@ -61,8 +61,22 @@ export const make = Effect.gen(function* () {
6161 const cli = yield * TangledCli ;
6262 const httpClient = yield * HttpClient . HttpClient ;
6363
64- const failure = ( operation : string , detail : string , reason : "failed" | "not-found" = "failed" ) =>
65- new PullRequestProviderError ( { provider : KIND , operation, reason, detail } ) ;
64+ const failure = (
65+ operation : string ,
66+ detail : string ,
67+ reason : PullRequestProviderError [ "reason" ] = "failed" ,
68+ ) => new PullRequestProviderError ( { provider : KIND , operation, reason, detail } ) ;
69+
70+ const cliFailure = ( operation : string , cause : TangledCliError ) =>
71+ failure (
72+ operation ,
73+ cause . detail ,
74+ cause . reason === "authentication"
75+ ? "unauthenticated"
76+ : cause . reason === "missing-cli"
77+ ? "missing-tool"
78+ : "failed" ,
79+ ) ;
6680
6781 const unsupported = ( operation : string , detail : string ) => ( ) =>
6882 Effect . fail ( failure ( operation , detail ) ) ;
@@ -81,12 +95,7 @@ export const make = Effect.gen(function* () {
8195 } )
8296 . pipe (
8397 Effect . map ( ( answer ) => numberPulls ( answer . items ) ) ,
84- Effect . mapError ( ( cause ) =>
85- failure (
86- input . operation ,
87- isTangledCliError ( cause ) ? cause . detail : "Tangled could not list pull requests." ,
88- ) ,
89- ) ,
98+ Effect . mapError ( ( cause ) => cliFailure ( input . operation , cause ) ) ,
9099 ) ;
91100 } ) ;
92101
@@ -209,7 +218,7 @@ export const make = Effect.gen(function* () {
209218 args : [ "pr" , "view" , entry . pull . rkey , "--repo" , input . repository ] ,
210219 schema : TangledPullViewSchema ,
211220 } )
212- . pipe ( Effect . mapError ( ( cause ) => failure ( input . operation , cause . detail ) ) ) ;
221+ . pipe ( Effect . mapError ( ( cause ) => cliFailure ( input . operation , cause ) ) ) ;
213222 return {
214223 pull : toChangeRequest (
215224 { ...entry , pull : { ...entry . pull , ...detail } } ,
@@ -234,7 +243,7 @@ export const make = Effect.gen(function* () {
234243 } )
235244 . pipe (
236245 Effect . map ( ( status ) => status . handle ?? status . did ?? "" ) ,
237- Effect . mapError ( ( cause ) => failure ( "getViewer" , cause . detail ) ) ,
246+ Effect . mapError ( ( cause ) => cliFailure ( "getViewer" , cause ) ) ,
238247 ) ,
239248
240249 listChangeRequests : ( input ) =>
0 commit comments