File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
components/profiles-modals Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,14 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
121
121
122
122
if (read !== null ) {
123
123
this .profileImportFilePath = files [0 ];
124
- this .profileImportContent = await ProfileUtils .parseYamlToExportFormat (read );
124
+ try {
125
+ this .profileImportContent = await ProfileUtils .parseYamlToExportFormat (read );
126
+ } catch (e : unknown ) {
127
+ const err = R2Error .fromThrownValue (e );
128
+ this .$store .commit (' error/handleError' , err )
129
+ this .closeModal ();
130
+ return ;
131
+ }
125
132
126
133
if (this .profileToOnlineMods .length === 0 ) {
127
134
this .activeStep = ' NO_PACKAGES_IN_IMPORT' ;
Original file line number Diff line number Diff line change @@ -125,6 +125,27 @@ export async function installModsToProfile(
125
125
126
126
export async function parseYamlToExportFormat ( yamlContent : string ) {
127
127
const parsedYaml = await yaml . parse ( yamlContent ) ;
128
+ if ( ! parsedYaml ) {
129
+ throw new R2Error (
130
+ 'Failed to parse yaml contents.' ,
131
+ 'Yaml parsing failed when trying to import profile via file (The contents of export.r2x file are invalid).' ,
132
+ 'Ensure that the profile import file isn\'t corrupted.'
133
+ )
134
+ }
135
+ if ( typeof parsedYaml . profileName !== 'string' ) {
136
+ throw new R2Error (
137
+ 'Failed to read profile name.' ,
138
+ 'Reading the profile name after parsing the yaml failed (export.r2x is missing the profileName field).' ,
139
+ 'Ensure that the profile import file isn\'t corrupted.'
140
+ )
141
+ }
142
+ if ( ! Array . isArray ( parsedYaml . mods ) ) {
143
+ throw new R2Error (
144
+ 'Failed to read mod list.' ,
145
+ 'Reading mods list after parsing the yaml failed (Mod list of export.r2x is invalid).' ,
146
+ 'Ensure that the profile import file isn\'t corrupted.'
147
+ )
148
+ }
128
149
return new ExportFormat (
129
150
parsedYaml . profileName ,
130
151
parsedYaml . mods . map ( ( mod : any ) => {
You can’t perform that action at this time.
0 commit comments