File tree Expand file tree Collapse file tree 2 files changed +26
-26
lines changed
components/profiles-modals Expand file tree Collapse file tree 2 files changed +26
-26
lines changed Original file line number Diff line number Diff line change @@ -117,28 +117,25 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
117
117
return ;
118
118
}
119
119
120
- let read: string | null = null ;
120
+ let read: string = ' ' ;
121
121
try {
122
122
read = await ProfileUtils .readProfileFile (files [0 ]);
123
123
} catch (e : unknown ) {
124
- if (e instanceof R2Error ) {
125
- this .$store .commit (' error/handleError' , e )
126
- this .closeModal ();
127
- return ;
128
- }
124
+ const err = R2Error .fromThrownValue (e );
125
+ this .$store .commit (' error/handleError' , err );
126
+ this .closeModal ();
127
+ return ;
129
128
}
130
129
131
- if (read ) {
132
- this .profileImportFilePath = files [0 ];
133
- this .profileImportContent = await ProfileUtils .parseYamlToExportFormat (read );
130
+ this .profileImportFilePath = files [0 ];
131
+ this .profileImportContent = await ProfileUtils .parseYamlToExportFormat (read );
134
132
135
- if (this .profileToOnlineMods .length === 0 ) {
136
- this .activeStep = ' NO_PACKAGES_IN_IMPORT' ;
137
- return ;
138
- }
139
-
140
- this .activeStep = ' REVIEW_IMPORT' ;
133
+ if (this .profileToOnlineMods .length === 0 ) {
134
+ this .activeStep = ' NO_PACKAGES_IN_IMPORT' ;
135
+ return ;
141
136
}
137
+
138
+ this .activeStep = ' REVIEW_IMPORT' ;
142
139
}
143
140
144
141
// Fired when user has accepted the mods to be imported in the review phase.
Original file line number Diff line number Diff line change @@ -180,20 +180,23 @@ export async function populateImportedProfile(
180
180
}
181
181
}
182
182
183
- export async function readProfileFile ( file : string ) {
184
- let read = '' ;
183
+ export async function readProfileFile ( file : string ) : Promise < string > {
184
+ let read : string | undefined ;
185
185
if ( file . endsWith ( '.r2x' ) ) {
186
186
read = ( await FsProvider . instance . readFile ( file ) ) . toString ( ) ;
187
187
} else if ( file . endsWith ( '.r2z' ) ) {
188
- const result : Buffer | null = await ZipProvider . instance . readFile ( file , "export.r2x" ) ;
189
- if ( ! result ) {
190
- throw new R2Error (
191
- 'Error when reading file contents' ,
192
- 'Reading the .r2z file contents failed. File contents be empty or corrupted.' ,
193
- 'Ensure that the imported profile file is valid.'
194
- ) ;
195
- }
196
- read = result . toString ( ) ;
188
+ await ZipProvider . instance . readFile ( file , "export.r2x" ) . then (
189
+ ( value ) => { read = value ?. toString ( ) } ,
190
+ ( ) => { return null ; }
191
+ ) ;
192
+ }
193
+
194
+ if ( ! read ) {
195
+ throw new R2Error (
196
+ 'Error when reading file contents' ,
197
+ 'Reading the .r2z file contents failed. File contents be empty or corrupted.' ,
198
+ 'Ensure that the imported profile file is valid.'
199
+ ) ;
197
200
}
198
201
return read ;
199
202
}
You can’t perform that action at this time.
0 commit comments