@@ -10,6 +10,7 @@ import { createAuthenticator } from './../workers/auth';
1010import { ReplexicaEngine } from '@replexica/sdk' ;
1111import { expandPlaceholderedGlob , createBucketLoader } from '../workers/bucket' ;
1212import { ensureLockfileExists } from './lockfile' ;
13+ import { ReplexicaCLIError } from '../utils/errors' ;
1314
1415export default new Command ( )
1516 . command ( 'i18n' )
@@ -34,13 +35,25 @@ export default new Command()
3435 const settings = await loadSettings ( flags . apiKey ) ;
3536
3637 if ( ! i18nConfig ) {
37- throw new Error ( 'i18n.json not found. Please run `replexica init` to initialize the project.' ) ;
38+ throw new ReplexicaCLIError ( {
39+ message : 'i18n.json not found. Please run `replexica init` to initialize the project.' ,
40+ docUrl : "i18nNotFound"
41+ } ) ;
3842 } else if ( ! i18nConfig . buckets || ! Object . keys ( i18nConfig . buckets ) . length ) {
39- throw new Error ( 'No buckets found in i18n.json. Please add at least one bucket containing i18n content.' ) ;
43+ throw new ReplexicaCLIError ( {
44+ message : "No buckets found in i18n.json. Please add at least one bucket containing i18n content." ,
45+ docUrl : "bucketNotFound"
46+ } ) ;
4047 } else if ( flags . locale && ! i18nConfig . locale . targets . includes ( flags . locale ) ) {
41- throw new Error ( `Source locale ${ i18nConfig . locale . source } does not exist in i18n.json locale.targets. Please add it to the list and try again.` ) ;
48+ throw new ReplexicaCLIError ( {
49+ message : `Source locale ${ i18nConfig . locale . source } does not exist in i18n.json locale.targets. Please add it to the list and try again.` ,
50+ docUrl : "localeTargetNotFound"
51+ } ) ;
4252 } else if ( flags . bucket && ! i18nConfig . buckets [ flags . bucket ] ) {
43- throw new Error ( `Bucket ${ flags . bucket } does not exist in i18n.json. Please add it to the list and try again.` ) ;
53+ throw new ReplexicaCLIError ( {
54+ message : `Bucket ${ flags . bucket } does not exist in i18n.json. Please add it to the list and try again.` ,
55+ docUrl : "bucketNotFound"
56+ } ) ;
4457 } else {
4558 ora . succeed ( 'Replexica configuration loaded' ) ;
4659 }
@@ -50,7 +63,10 @@ export default new Command()
5063 try {
5164 lockfileResult = await ensureLockfileExists ( ) ;
5265 } catch ( error : any ) {
53- throw new Error ( `Failed to ensure lockfile exists: ${ error . message } ` ) ;
66+ throw new ReplexicaCLIError ( {
67+ message : `Failed to ensure lockfile exists: ${ error . message } ` ,
68+ docUrl : "lockFiletNotFound"
69+ } ) ;
5470 }
5571 if ( lockfileResult === 'exists' ) {
5672 ora . succeed ( `Lockfile exists` ) ;
@@ -65,7 +81,10 @@ export default new Command()
6581 } ) ;
6682 const auth = await authenticator . whoami ( ) ;
6783 if ( ! auth ) {
68- throw new Error ( 'Not authenticated' ) ;
84+ throw new ReplexicaCLIError ( {
85+ message : 'Not authenticated' ,
86+ docUrl : "authError"
87+ } ) ;
6988 }
7089
7190 ora . start ( 'Connecting to Replexica AI engine' ) ;
@@ -76,7 +95,10 @@ export default new Command()
7695 apiUrl : settings . auth . apiUrl ,
7796 } ) ;
7897 } catch ( error : any ) {
79- throw new Error ( `Failed to initialize ReplexicaEngine: ${ error . message } ` ) ;
98+ throw new ReplexicaCLIError ( {
99+ message : `Failed to initialize ReplexicaEngine: ${ error . message } ` ,
100+ docUrl : "failedReplexicaEngine"
101+ } ) ;
80102 }
81103 ora . succeed ( 'Replexica AI engine connected' ) ;
82104
@@ -102,7 +124,10 @@ export default new Command()
102124 }
103125 }
104126 } catch ( error : any ) {
105- throw new Error ( `Failed to expand placeholdered globs: ${ error . message } ` ) ;
127+ throw new ReplexicaCLIError ( {
128+ message : `Failed to expand placeholdered globs: ${ error . message } ` ,
129+ docUrl : "placeHolderFailed"
130+ } ) ;
106131 }
107132
108133 const lockfileProcessor = createLockfileProcessor ( ) ;
@@ -164,7 +189,10 @@ export default new Command()
164189 } ;
165190
166191 if ( flags . frozen && ( payloadStats . processable > 0 || payloadStats . deleted > 0 ) ) {
167- throw new Error ( `Translations are not up to date. Run the command without the --frozen flag to update the translations, then try again.` ) ;
192+ throw new ReplexicaCLIError ( {
193+ message : `Translations are not up to date. Run the command without the --frozen flag to update the translations, then try again.` ,
194+ docUrl : "translationFailed"
195+ } ) ;
168196 }
169197
170198 let processedPayload : Record < string , string > = { } ;
0 commit comments