Skip to content

Commit 9766bc9

Browse files
committed
lint: improve logging of potential objects
Stop using tostring when JSON.stringify is better suited or just specify object parts. Signed-off-by: Chris. Webster <[email protected]>
1 parent d61c1b1 commit 9766bc9

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

lib/ci-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export class CIHelper {
329329
const comment2 = `Found multiple candidates in ${maintainerRepo}:\n${
330330
gitsterBranch};\n\nUsing the first one.`;
331331
const url2 = await this.github.addPRComment(prKey, comment2);
332-
console.log(`Added comment about ${gitsterBranch}: ${url2}`);
332+
console.log(`Added comment ${url2.id} about ${gitsterBranch}: ${url2.url}`);
333333

334334
gitsterBranch = gitsterBranch.substring(0, newline);
335335
}
@@ -342,7 +342,7 @@ export class CIHelper {
342342
notesUpdated = true;
343343

344344
const url = await this.github.addPRComment(prKey, comment);
345-
console.log(`Added comment about ${gitsterBranch}: ${url}`);
345+
console.log(`Added comment ${url.id} about ${gitsterBranch}: ${url.url}`);
346346
}
347347
}
348348

@@ -372,7 +372,7 @@ export class CIHelper {
372372
const comment = `This patch series was integrated into ${branch} via https://github.com/${
373373
this.config.repo.baseOwner}/${this.config.repo.name}/commit/${mergeCommit}.`;
374374
const url = await this.github.addPRComment(prKey, comment);
375-
console.log(`Added comment about ${branch}: ${url}`);
375+
console.log(`Added comment ${url.id} about ${branch}: ${url.url}`);
376376
}
377377
}
378378

@@ -527,7 +527,7 @@ GitGitGadget needs an email address to Cc: you on your contribution, so that you
527527
comment = await this.github.getPRComment(repositoryOwner, commentID);
528528
} catch (e) {
529529
if (e instanceof RequestError && e.status === 404 ) {
530-
console.log(`Comment ${commentID} not found; doing nothing: '${e.toString()}'`);
530+
console.log(`Comment ${commentID} not found; doing nothing:\n'${JSON.stringify(e, null, 2)}'`);
531531
return;
532532
} else {
533533
throw e;

lib/github-glue.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ export class GitHubGlue {
314314

315315
response.data.map((pr) => {
316316
if (!pr.user || !pr.base.repo.owner) {
317-
throw new Error(`PR ${pr.number} is missing information. ${
318-
pr.toString()}`);
317+
throw new Error(`PR ${pr.number} is missing information.\n${JSON.stringify(pr, null, 2)}`);
319318
}
320319

321320
result.push({
@@ -351,8 +350,8 @@ export class GitHubGlue {
351350

352351
const pullRequest = response.data;
353352
if (!pullRequest.user) {
354-
throw new Error(`PR ${pullRequest.number} is missing information. ${
355-
pullRequest.toString()}`);
353+
throw new Error(`PR ${pullRequest.number} is missing information.\n${
354+
JSON.stringify(pullRequest, null, 2)}`);
356355
}
357356

358357
return {
@@ -390,8 +389,8 @@ export class GitHubGlue {
390389
const prNumber = match ? parseInt(match[1], 10) : -1;
391390

392391
if (!response.data.user) {
393-
throw new Error(`PR ${prNumber} comment is missing information. ${
394-
response.data.toString()}`);
392+
throw new Error(`PR ${prNumber} comment is missing information.\n${
393+
JSON.stringify(response.data, null, 2)}`);
395394
}
396395

397396
return {
@@ -418,8 +417,7 @@ export class GitHubGlue {
418417
const result: IPRCommit[] = [];
419418
response.data.map((cm) => {
420419
if (!cm.commit.committer || !cm.commit.author || !cm.sha) {
421-
throw new Error(`Commit information missing for PR ${
422-
prNumber} - ${cm.toString()}`);
420+
throw new Error(`Commit information missing for PR ${prNumber}:\n${JSON.stringify(cm, null, 2)}`);
423421
}
424422

425423
const committer = cm.commit.committer;

lib/misc-action.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ async function getExternalConfig(file: string): Promise<IConfig> {
6969

7070
function lintConfig(config: IConfig): void {
7171
if (!config.hasOwnProperty("project")) {
72-
throw new Error(`User configurations must have a 'project:'. Not found in ${path}`);
72+
throw new Error(`User configurations must have a 'project:'. Not found in:\n${
73+
JSON.stringify(config, null, 2)}`);
7374
}
7475

7576
if (!config.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
76-
throw new Error(`Invalid 'owner' ${config.repo.owner} in ${path}`);
77+
throw new Error(`Invalid 'owner' ${config.repo.owner} in\n${JSON.stringify(config, null, 2)}`);
7778
}
7879

7980
if (!config.repo.baseOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
80-
throw new Error(`Invalid 'baseOwner' ${config.repo.baseOwner} in ${path}`);
81+
throw new Error(`Invalid 'baseOwner' ${config.repo.baseOwner} in\n${JSON.stringify(config, null, 2)}`);
8182
}
8283
}

lib/pull-action.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ async function getExternalConfig(file: string): Promise<IConfig> {
6161

6262
function lintConfig(config: IConfig): void {
6363
if (!config.hasOwnProperty("project")) {
64-
throw new Error(`User configurations must have a 'project:'. Not found in ${path}`);
64+
throw new Error(`User configurations must have a 'project:'. Not found in\n${
65+
JSON.stringify(config, null, 2)}`);
6566
}
6667

6768
if (!config.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
68-
throw new Error(`Invalid 'owner' ${config.repo.owner} in ${path}`);
69+
throw new Error(`Invalid 'owner' ${config.repo.owner} in\n${JSON.stringify(config, null, 2)}`);
6970
}
7071

7172
if (!config.repo.baseOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
72-
throw new Error(`Invalid 'baseOwner' ${config.repo.baseOwner} in ${path}`);
73+
throw new Error(`Invalid 'baseOwner' ${config.repo.baseOwner} in\n${JSON.stringify(config, null, 2)}`);
7374
}
7475
}

script/misc-helper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,19 @@ const commandOptions = commander.opts<ICommanderOptions>();
447447
});
448448

449449
async function getExternalConfig(file: string): Promise<IConfig> {
450-
const newConfig = await loadConfig(path.resolve(file));
450+
const filePath = path.resolve(file);
451+
const newConfig = await loadConfig(filePath);
451452

452453
if (!newConfig.hasOwnProperty("project")) {
453-
throw new Error(`User configurations must have a 'project:'. Not found in ${path}`);
454+
throw new Error(`User configurations must have a 'project:'. Not found in ${filePath}`);
454455
}
455456

456457
if (!newConfig.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
457-
throw new Error(`Invalid 'owner' ${newConfig.repo.owner} in ${path}`);
458+
throw new Error(`Invalid 'owner' ${newConfig.repo.owner} in ${filePath}`);
458459
}
459460

460461
if (!newConfig.repo.baseOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
461-
throw new Error(`Invalid 'baseOwner' ${newConfig.repo.baseOwner} in ${path}`);
462+
throw new Error(`Invalid 'baseOwner' ${newConfig.repo.baseOwner} in ${filePath}`);
462463
}
463464

464465
return newConfig;

0 commit comments

Comments
 (0)