File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -139,20 +139,27 @@ export class MicropythonFsHex implements FsInterface {
139
139
* instance.
140
140
*
141
141
* @throws {Error } When there is a problem reading the files from the hex.
142
- * @throws {Error } When a filename already exists in this instance.
142
+ * @throws {Error } When a filename already exists in this instance (all other
143
+ * files are still imported).
143
144
*
144
145
* @param intelHex - MicroPython hex string with files.
145
146
* @param overwrite - Flag to overwrite existing files in this instance.
146
147
* @returns A filename list of added files.
147
148
*/
148
149
importFilesFromIntelHex ( intelHex : string , overwrite ?: boolean ) : string [ ] {
149
150
const files = getIntelHexFiles ( intelHex ) ;
151
+ const existingFiles : string [ ] = [ ] ;
150
152
Object . keys ( files ) . forEach ( ( filename ) => {
151
153
if ( ! overwrite && this . exists ( filename ) ) {
152
- throw new Error ( `File "${ filename } " from hex already exists.` ) ;
154
+ existingFiles . push ( filename ) ;
155
+ } else {
156
+ this . write ( filename , files [ filename ] ) ;
153
157
}
154
- this . write ( filename , files [ filename ] ) ;
155
158
} ) ;
159
+ // Only throw the error at the end so that all other files are imported
160
+ if ( existingFiles . length ) {
161
+ throw new Error ( `Files "${ existingFiles } " from hex already exists.` ) ;
162
+ }
156
163
return Object . keys ( files ) ;
157
164
}
158
165
You can’t perform that action at this time.
0 commit comments