11import path from "path"
22import { fileURLToPath } from "url"
3+ import { Schema } from "effect"
34import { Global } from "@opencode-ai/core/global"
45
56type BaseReference = {
@@ -23,6 +24,43 @@ export type FileReference = BaseReference & {
2324
2425export type Reference = RemoteReference | FileReference
2526
27+ export class InvalidRepositoryReferenceError extends Schema . TaggedErrorClass < InvalidRepositoryReferenceError > ( ) (
28+ "RepositoryInvalidReferenceError" ,
29+ {
30+ repository : Schema . String ,
31+ message : Schema . String ,
32+ } ,
33+ ) { }
34+
35+ export class UnsupportedLocalRepositoryError extends Schema . TaggedErrorClass < UnsupportedLocalRepositoryError > ( ) (
36+ "RepositoryUnsupportedLocalRepositoryError" ,
37+ {
38+ repository : Schema . String ,
39+ message : Schema . String ,
40+ } ,
41+ ) { }
42+
43+ export class InvalidRepositoryBranchError extends Schema . TaggedErrorClass < InvalidRepositoryBranchError > ( ) (
44+ "RepositoryInvalidBranchError" ,
45+ {
46+ branch : Schema . String ,
47+ message : Schema . String ,
48+ } ,
49+ ) { }
50+
51+ export type RepositoryError =
52+ | InvalidRepositoryReferenceError
53+ | UnsupportedLocalRepositoryError
54+ | InvalidRepositoryBranchError
55+
56+ export function isRepositoryError ( error : unknown ) : error is RepositoryError {
57+ return (
58+ error instanceof InvalidRepositoryReferenceError ||
59+ error instanceof UnsupportedLocalRepositoryError ||
60+ error instanceof InvalidRepositoryBranchError
61+ )
62+ }
63+
2664function normalizeRepositoryInput ( input : string ) {
2765 return input
2866 . trim ( )
@@ -147,16 +185,27 @@ export function isRemoteRepositoryReference(reference: Reference): reference is
147185
148186export function parseRemoteRepositoryReference ( input : string ) {
149187 const reference = parseRepositoryReference ( input )
150- if ( ! reference ) throw new Error ( "Repository must be a git URL, host/path reference, or GitHub owner/repo shorthand" )
151- if ( ! isRemoteRepositoryReference ( reference ) ) throw new Error ( "Local file repositories are not supported" )
188+ if ( ! reference ) {
189+ throw new InvalidRepositoryReferenceError ( {
190+ repository : input ,
191+ message : "Repository must be a git URL, host/path reference, or GitHub owner/repo shorthand" ,
192+ } )
193+ }
194+ if ( ! isRemoteRepositoryReference ( reference ) ) {
195+ throw new UnsupportedLocalRepositoryError ( {
196+ repository : input ,
197+ message : "Local file repositories are not supported" ,
198+ } )
199+ }
152200 return reference
153201}
154202
155203export function validateRepositoryBranch ( branch : string ) {
156204 if ( ! / ^ [ A - Z a - z 0 - 9 / _ . - ] + $ / . test ( branch ) || branch . startsWith ( "-" ) || branch . includes ( ".." ) ) {
157- throw new Error (
158- "Branch must contain only alphanumeric characters, /, _, ., and -, and cannot start with - or contain .." ,
159- )
205+ throw new InvalidRepositoryBranchError ( {
206+ branch,
207+ message : "Branch must contain only alphanumeric characters, /, _, ., and -, and cannot start with - or contain .." ,
208+ } )
160209 }
161210}
162211
0 commit comments