Skip to content

Commit 0d5b118

Browse files
committed
better error info: print image's origin_name & matched_name
1 parent b6902e1 commit 0d5b118

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,8 @@ export function log(msg: any) { Stdlib.log(msg); alllog += msg + '\n'; }
112112
export function log_err(msg: any) { Stdlib.log(msg); errlog += msg + '\n'; alllog += msg + '\n'; }
113113
export function showdump(o: any) { alert(Stdlib.listProps(o)); }
114114

115+
export function str_filename_pair(file_orign: string, file_matched: string): string {
116+
return file_orign + "(" + file_matched + ")";
117+
}
118+
115119
} // namespace LabelPlus

src/importer.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface ImageWorkspace {
3737
interface ImageInfo {
3838
ws: ImageWorkspace;
3939
name: string;
40+
name_pair: string;
4041
labels: LpLabel[];
4142
};
4243

@@ -319,7 +320,7 @@ function closeImage(img: ImageInfo, saveType: OptionOutputType = OptionOutputTyp
319320
asCopy = true;
320321
break;
321322
default:
322-
log_err("unkown save type: " + saveType);
323+
log_err(img.name_pair + ": unkown save type " + saveType);
323324
return false
324325
}
325326

@@ -399,32 +400,34 @@ export function importFiles(custom_opts: CustomOptions): boolean
399400

400401
// 遍历所选图片
401402
for (let i = 0; i < opts.imageSelected.length; i++) {
402-
let originName :string = opts.imageSelected[i].file; // 翻译文件中的图片文件名
403-
let filename: string = opts.imageSelected[i].matched_file;
403+
let orgin_name :string = opts.imageSelected[i].file; // 翻译文件中的图片文件名
404+
let matched_name: string = opts.imageSelected[i].matched_file;
405+
let name_pair = LabelPlus.str_filename_pair(orgin_name, matched_name);
404406

405-
log('[' + originName + '] in processing...' );
406-
if (opts.ignoreNoLabelImg && lpFile?.images[originName].length == 0) { // ignore img with no label
407+
log(name_pair + 'in processing...' );
408+
if (opts.ignoreNoLabelImg && lpFile?.images[orgin_name].length == 0) { // ignore img with no label
407409
log('no label, ignored...');
408410
continue;
409411
}
410-
let ws = openImageWorkspace(filename, template_path);
412+
let ws = openImageWorkspace(matched_name, template_path);
411413
if (ws == null) {
412-
log_err(filename + ": " + I18n.ERROR_FILE_OPEN_FAIL);
414+
log_err(name_pair + ": " + I18n.ERROR_FILE_OPEN_FAIL);
413415
continue;
414416
}
415417

416418
let img_info: ImageInfo = {
417419
ws: ws,
418-
name: filename,
419-
labels: lpFile.images[originName],
420+
name: matched_name,
421+
name_pair: name_pair,
422+
labels: lpFile.images[orgin_name],
420423
};
421424
if (!importImage(img_info)) {
422-
log_err(filename + ": import label failed");
425+
log_err(name_pair + ": import label failed");
423426
}
424427
if (!closeImage(img_info, opts.outputType)) {
425-
log_err(filename + ": " + I18n.ERROR_FILE_SAVE_FAIL);
428+
log_err(name_pair + ": " + I18n.ERROR_FILE_SAVE_FAIL);
426429
}
427-
log(filename + ": done");
430+
log(name_pair + ": done");
428431
}
429432
log("All Done!");
430433
return true;

0 commit comments

Comments
 (0)