Skip to content

Commit 8621f3e

Browse files
optimize log for user
1 parent 29c68f8 commit 8621f3e

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

packages/core/src/diff-file.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export class DiffFile {
361361
if (!hasSymbolChanged && oldFileContent === newFileContent) {
362362
if (__DEV__) {
363363
console.warn(
364-
'the composed "oldFileContent" and "newFileContent" are the same, maybe the "diff" string is not valid'
364+
'[@git-diff-view/core] The composed "oldFileContent" and "newFileContent" are identical. This might indicate an invalid "diff" string.'
365365
);
366366
}
367367
return;
@@ -465,7 +465,7 @@ export class DiffFile {
465465
diffLine?.text !== fileLine?.value
466466
) {
467467
console.warn(
468-
`there are some mismatch from the 'oldFileContent' and 'diff' at line: ${line}, please make sure the 'oldFileContent' is correct`
468+
`[@git-diff-view/core] Mismatch detected between 'oldFileContent' and 'diff' at line ${line}. Please verify the 'oldFileContent' is correct.`
469469
);
470470
break;
471471
}
@@ -478,7 +478,7 @@ export class DiffFile {
478478
diffLine?.text !== fileLine?.value
479479
) {
480480
console.warn(
481-
`there are some mismatch from the 'newFileContent' and 'diff' at line: ${line}, please make sure the 'newFileContent' is correct`
481+
`[@git-diff-view/core] Mismatch detected between 'newFileContent' and 'diff' at line ${line}. Please verify the 'newFileContent' is correct.`
482482
);
483483
break;
484484
}
@@ -581,7 +581,7 @@ export class DiffFile {
581581
typedI.hunkInfo.newStartIndex &&
582582
typedI.hunkInfo.oldStartIndex !== typedI.hunkInfo.newStartIndex
583583
) {
584-
console.warn("the first hunk should start with the same line number");
584+
console.warn("[@git-diff-view/core] The first hunk should start with the same line number.");
585585
}
586586

587587
prevHunkLine = typedI;
@@ -614,7 +614,7 @@ export class DiffFile {
614614
if (__DEV__) {
615615
if (item.oldLineNumber <= maxOldLineNumber) {
616616
console.warn(
617-
'the "lineNumber" from "diff" should be in ascending order, maybe current "diff" string is not a valid "diff" string'
617+
'[@git-diff-view/core] Line numbers in "diff" must be in ascending order. This might indicate an invalid "diff" string.'
618618
);
619619
}
620620

@@ -630,7 +630,7 @@ export class DiffFile {
630630
if (__DEV__) {
631631
if (item.newLineNumber <= maxNewLineNumber) {
632632
console.warn(
633-
'the "lineNumber" from "diff" should be in ascending order, maybe current "diff" string is not a valid "diff" string'
633+
'[@git-diff-view/core] Line numbers in "diff" must be in ascending order. This might indicate an invalid "diff" string.'
634634
);
635635
}
636636

@@ -670,7 +670,7 @@ export class DiffFile {
670670
if (this.#composeByMerge && !this.#composeByFullMerge) {
671671
if (__DEV__) {
672672
console.error(
673-
`this instance can not do syntax because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'`
673+
"[@git-diff-view/core] Syntax highlighting failed due to missing data. Consider using '_getFullBundle' and '_mergeFullBundle' instead of 'getBundle' and 'mergeBundle'."
674674
);
675675
}
676676

@@ -744,7 +744,7 @@ export class DiffFile {
744744
if (__DEV__) {
745745
if (this._diffList.some((l) => l) && !this.#diffLines.length) {
746746
console.warn(
747-
"the hunks from the diff string is empty, maybe the diff string is not a valid diff string, please check the diff string format or the diff string itself"
747+
"[@git-diff-view/core] No hunks found in the diff string. Please check the diff format and content."
748748
);
749749
}
750750
}
@@ -787,7 +787,7 @@ export class DiffFile {
787787

788788
if (__DEV__ && !this.#oldFileResult && !this.#newFileResult && this.#composeByMerge && !this.#composeByFullMerge) {
789789
console.error(
790-
"this instance can not `buildSplitDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
790+
"[@git-diff-view/core] this instance can not `buildSplitDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
791791
);
792792
}
793793

@@ -888,7 +888,7 @@ export class DiffFile {
888888
const prevHunkLine = oldDiffLine?.prevHunkLine || newDiffLine.prevHunkLine;
889889
if (prevHunkLine.isFirst) {
890890
if (__DEV__ && Number.isFinite(hideStart)) {
891-
console.warn("the first hunk can not have a previous diff line");
891+
console.warn("[@git-diff-view/core] The first hunk cannot have a previous diff line.");
892892
}
893893
prevHunkLine.splitInfo = {
894894
...prevHunkLine.hunkInfo,
@@ -973,7 +973,7 @@ export class DiffFile {
973973

974974
if (__DEV__ && !this.#oldFileResult && !this.#newFileResult && this.#composeByMerge && !this.#composeByFullMerge) {
975975
console.error(
976-
"this instance can not `buildUnifiedDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
976+
"[@git-diff-view/core] this instance can not `buildUnifiedDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
977977
);
978978
}
979979

@@ -1066,7 +1066,7 @@ export class DiffFile {
10661066
const prevHunkLine = oldDiffLine?.prevHunkLine || newDiffLine.prevHunkLine;
10671067
if (prevHunkLine.isFirst) {
10681068
if (__DEV__ && Number.isFinite(hideStart)) {
1069-
console.warn("the first hunk can not have a previous diff line");
1069+
console.warn("[@git-diff-view/core] The first hunk cannot have a previous diff line.");
10701070
}
10711071
prevHunkLine.unifiedInfo = {
10721072
...prevHunkLine.hunkInfo,
@@ -1221,7 +1221,7 @@ export class DiffFile {
12211221
} else if (dir === "up") {
12221222
if (current.isLast) {
12231223
if (__DEV__) {
1224-
console.error("the last hunk can not expand up!");
1224+
console.error("[@git-diff-view/core] The last hunk cannot expand up!");
12251225
}
12261226
return;
12271227
}
@@ -1251,7 +1251,7 @@ export class DiffFile {
12511251
} else if (dir === "up-all") {
12521252
if (current.isLast) {
12531253
if (__DEV__) {
1254-
console.error("the last hunk can not expand up!");
1254+
console.error("[@git-diff-view/core] The last hunk cannot expand up!");
12551255
}
12561256
return;
12571257
}
@@ -1352,7 +1352,7 @@ export class DiffFile {
13521352
} else if (dir === "up") {
13531353
if (current.isLast) {
13541354
if (__DEV__) {
1355-
console.error("the last hunk can not expand up!");
1355+
console.error("[@git-diff-view/core] The last hunk cannot expand up!");
13561356
}
13571357
return;
13581358
}
@@ -1380,7 +1380,7 @@ export class DiffFile {
13801380
} else if (dir === "up-all") {
13811381
if (current.isLast) {
13821382
if (__DEV__) {
1383-
console.error("the last hunk can not expand up!");
1383+
console.error("[@git-diff-view/core] The last hunk cannot expand up!");
13841384
}
13851385
return;
13861386
}
@@ -1678,11 +1678,11 @@ export class DiffFile {
16781678
this.#isCloned = true;
16791679

16801680
if (__DEV__ && this._version_ !== data.version) {
1681-
console.error("the version of the `diffInstance` is not match, some error may happen");
1681+
console.error("[@git-diff-view/core] The version of the `diffInstance` does not match. Some errors may occur.");
16821682
}
16831683

16841684
if (__DEV__ && !data.hasInitRaw) {
1685-
console.error(`there are not a valid bundle data, try to call 'initRaw' function before merge / getBundle`);
1685+
console.error("[@git-diff-view/core] Invalid bundle data. Try calling the 'initRaw' function before merge / getBundle.");
16861686
}
16871687

16881688
if (notifyUpdate) {

packages/core/src/file.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (__DEV__ && typeof globalThis !== "undefined") {
1818
globalThis[devKey] = globalThis[devKey].filter((i) => i !== map);
1919

2020
if (globalThis[devKey].length > 0) {
21-
console.warn("there are multiple instance of @git-diff-view/core in current environment!");
21+
console.warn("[@git-diff-view/core] Multiple instances of @git-diff-view/core detected in the current environment.");
2222
}
2323

2424
globalThis[devKey].push(map);
@@ -111,7 +111,7 @@ export class File {
111111

112112
if (this.rawLength > finalHighlighter.maxLineToIgnoreSyntax) {
113113
if (__DEV__) {
114-
console.warn(`ignore syntax for current file, because the rawLength is too long: ${this.rawLength}`);
114+
console.warn(`[@git-diff-view/core] Ignoring syntax highlighting for the current file as the raw length exceeds the threshold: ${this.rawLength}`);
115115
}
116116
return;
117117
}
@@ -193,12 +193,12 @@ export class File {
193193
#doCheck() {
194194
if (this.rawLength && this.syntaxLength) {
195195
if (this.rawLength !== this.syntaxLength) {
196-
console.warn("the rawLength not match for the syntaxLength");
196+
console.warn("[@git-diff-view/core] The rawLength does not match the syntaxLength.");
197197
}
198198
Object.values(this.syntaxFile).forEach(({ value, lineNumber }) => {
199199
if (value !== this.rawFile[lineNumber]) {
200-
console.log(
201-
"some line not match:" + value + " __ " + this.rawFile[lineNumber] + " __ at: " + lineNumber + " lineNumber"
200+
console.warn(
201+
"[@git-diff-view/core] Content mismatch detected at line " + lineNumber + ": " + value + " !== " + this.rawFile[lineNumber]
202202
);
203203
}
204204
});

packages/core/src/parse/diff-parse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class DiffParser {
207207
if (this.lineStartsWith("Binary files ") && this.lineEndsWith("differ")) {
208208
if (__DEV__) {
209209
console.warn(
210-
"Found binary file marker in diff header, @git-diff-view/core currently does not support rendering binary diffs"
210+
"[@git-diff-view/core] Binary file marker detected in diff header. Rendering binary diffs is currently not supported."
211211
);
212212
}
213213
return { isBinary: true };
@@ -219,7 +219,7 @@ export class DiffParser {
219219

220220
if (this.lineStartsWith("+++")) {
221221
if (__DEV__ && !hasMinus) {
222-
console.error("Invalid diff header, found +++ line before --- line");
222+
console.error("[@git-diff-view/core] Invalid diff header: found '+++' line before '---' line.");
223223
}
224224
return { isBinary: false };
225225
}

0 commit comments

Comments
 (0)